|
What's the "correct" technique for doing a modal loop in C#/Winforms? In MFC, you could use CWnd::RunModalLoop() or implement something similar, and then call EndModalLoop() to end it. Is there something similar already in place in Winforms for this? I haven't found it yet and have the nast suspicion I will need to do this from scratch.
If I do need to write this, do I want to use the raw Win32 message loop calls, or something involving Application.DoEvents()?
Here's what I'd like to happen:
Main UI thread:
send a message to a server via sockets
wait in a modal loop until the server responds or some other error condition is hit
Socket handling thread:
read socket data from server, notify main UI thread when done
|
|
|
|
|
Hi Jim,
IMO that is a strange question. I've never seen an explicit message loop in managed code.
If I understood your question correctly, this is what I might(*) do:
- main thread starts a BackgroundWorker that does the server communication and waits for results;
- meanwhile main thread shows a dialog explaining what is going on, possibly offering a progress indication, and probably offering a "cancel" button.
- when the BGW decides all is done, or when it gives up, show the final status in the existing dialog and either change the "cancel" button into an "OK" button, or, after 2 seconds, close the dialog (by which action the main thread continues).
(*) the alternative is not having a modal dialog at all (since that blocks the entire app), and use a modeless dialog instead. That of course requires a different synchronization technique, as now the main thread would never wait.
[ADDED]
FYI: this[^] may interest you.
[/ADDED]
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Monday, February 8, 2010 3:53 PM
|
|
|
|
|
Hello,
I have a datagridviewcheckboxcell in a datagrid which is displayed properly . I want a text next to the box. Which property should I use?
Thank you
Pritha
|
|
|
|
|
As far as I am aware, there is no property to put text beside the checkbox - the text goes into the column heading where it it less intrusive for the user. If you really must do this, you will probably have to create your own custom control, based on a DataGridViewCheckBoxCell, and incorporate the text yourself. I haven't tried this, so I have no idea what problems you are going to face.
Are you sure you need it, given that you can only have true / false / grey in the checkbox anyway?If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Thanks you for your reply
I will have to derive a class from DataGridViewCheckBoxCell
Thanks
|
|
|
|
|
Hi all,
I'm sure that this has been asked quite a bit but I can not find a answer to it. I know that I have seen C# prototypes like in C/C++ .h/.cpp files but can not remember how it is done. In the several searches I have done the closest I can come to are partial classes. Is this the right direction? If so what is the proper syntax for declaring them? I like to have the decelerations in a separate file/location so I don't have to search through lines of code just to get to the functions decelerations.
Thanks for the help!!!!
-Andy
|
|
|
|
|
I could be wrong, but I don't think C# has prototypes in the same way as C or C++ - the only ones I can think of are for abstract members or interfaces. If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Thanks!
I know that I had seen this done in a Article Source File but don't remember how it was done. If this is not a "Best Practice" what is? I am new to C#
Thanks again ...
-Andy
|
|
|
|
|
The only thing I can think of that even comes close to a "prototype" would be a delegate definition.
|
|
|
|
|
Now why did you get downvoted.. still that stupid guy from yesterday/some days back/whatever?
|
|
|
|
|
There's some wierd univoting going on around here Fived to compensate as well as for a good answer!
|
|
|
|
|
C# does not use prototypes; class definition information is culled from the object files where it is stored as metadata. Take a look through MSDN for more information on the C# language and compiler. MVP 2010 - are they mad?
|
|
|
|
|
Hello there!
I have an Xdocument created programatically, and i wan't to zip it and save it in a gzip file.
Now my problem is that i want the name of the zip file, to be independent from the name of the zipped file...
i.e the zip file will be foo.gz, and the file inside will be test.xml. Now i have read that
by using -GZipStream- you can't actually give a name to your file. i have managed to zip files, but not name them... any ideas?
Here is how i do it at the moment
private void Compress(XDocument doc, string fullUserFilePath)
{
byte[] buffer;
MemoryStream memoryStream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(memoryStream);
doc.Save(writer);
writer.Close();
memoryStream.Position = 0;
buffer = new byte[memoryStream.Length];
memoryStream.Read(buffer, 0, buffer.Count());
using (FileStream outfile = new FileStream(fullUserFilePath, FileMode.Create, FileAccess.Write))
{
using (GZipStream stream = new GZipStream(outfile, CompressionMode.Compress))
{
using (BinaryWriter sw = new BinaryWriter(stream))
{
sw.Write(buffer);
}
}
}
}
|
|
|
|
|
What is the value of fullUserFilePath? Surely that will determine the name of the zip file Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
yes that is the name of the zip file, but it names the file within it like that, whereas i want to name it differently.
so at the line:
using (GZipStream stream = new GZipStream(outfile, CompressionMode.Compress))
it would be ideal if i could do something like:
using (GZipStream stream = new GZipStream(outfile,"myfileName.xml", CompressionMode.Compress))
but that's not possible ...
|
|
|
|
|
I see what you mean, what if you rename the zipped file? you can use System.IO.File.Move(...) for that. Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
the problem is that after compression, i want to rename the zipped file(within the zip file...)
the name of the zip file is correct...
|
|
|
|
|
So do it the other way around, make the name of the gzipped file correct and change the filename of the result
|
|
|
|
|
Like harold says, do it the other way around.
You may want to consider creating a 'temp' zip file named the same as you want the internal file to be called. Then you the File.Move function to move that 'temp' file to that specified in fullUserFilePath
Just remember to be careful where you create temp files, Application.Startup (or similar) can cause write issues with certain user restrictions. Maybe 'ApplicationData' or something like that would be fine. Your choice thouLife goes very fast. Tomorrow, today is already yesterday.
modified on Monday, February 8, 2010 1:20 PM
|
|
|
|
|
Or you could use SharpZipLib[^], it's free and places no restrictions on your license if you link with the binary. The compression ratio is better and it allows you to properly handle and create zip files (the problem you have does not occur with SharpZipLib)
|
|
|
|
|
Friends,
I hope you can help me. I am developing a new project and this project I have several screens. Well, I would like to create a screen through her name and that name is the same class name of the screen.
Example:
I create a new screen, and put her name as formCadastro. Now, in my base form, I would go to a function the string value "formCadastro" function and open the screen with the same name.
Is it possible? I tried to work a little with the System.Windows.Forms.Form class but I could not ... Thank you for your help.
Success for All
|
|
|
|
|
Like this[^] ?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Friend, it would be nearly so. But I wanted something simpler. There is to create a container of the screens?
I am studying the example. Thanks
|
|
|
|
|
Have you tried a switch statement?
switch(inputname){
case "Screen1": Screen1 s1 = new Screen1();
s1.ShowDialog();
break;
case "Screen2": Screen2 s2 = new Screen2();
s2.ShowDialog();
break;
default:
break;
} V.
|
|
|
|
|
Friend, this will not work.
There are many screens, and would like to develop a generic method.
Thanks!
|
|
|
|