Dialog Box
-
I am fairly new to C#, how do I get a dialog box to fully display before executing any code. There is no user interaction, but I display messages during the execution, but they never are seen since the box does not finish displaying until the code is finished.
-
I am fairly new to C#, how do I get a dialog box to fully display before executing any code. There is no user interaction, but I display messages during the execution, but they never are seen since the box does not finish displaying until the code is finished.
Hi, the code you put in the form's constructor, or in its Load handler, will execute before the form is visible. And any code you put in any of its event handlers will run on the main or "GUI thread" at the expense of a good user interaction. If you have a lenghty operation, you really should use one (or more) separate threads, either simply instances of Thread, or members of ThreadPool, or a BackgroundWorker. That way the long operation is handled independent of the user interaction, so the form would continue to respond to moves, resizes, repaints, etc. If the long operation needs to start all by itself, launch the thread(s) from inside the form's Load handler. If it should be launched by say a button click, you obviously would put the thread launch code in the Button's Click handler. Warning: as soon as you start using separate threads you will need Control.InvokeRequired and Control.Invoke() to allow such threads to access the Form or its Controls, because only one thread is allowed to directly access Controls (the thread that created them). There are plenty of examples of this, at CodeProject and everywhere else. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
-
I am fairly new to C#, how do I get a dialog box to fully display before executing any code. There is no user interaction, but I display messages during the execution, but they never are seen since the box does not finish displaying until the code is finished.
Hard to know for sure, but I'd guess that the problem is that you've got a form showing modelessly ( show instead of showdialog ) and it doesn't show while the thread is busy with other processing you do directly after. Call ShowDialog and your code will stop until the form is closed. Use a seperate thread to do processing and keep your UI working, or call Application.DoEvents to force a paint event. Hard to say if this is the problem, without seeing the code.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I am fairly new to C#, how do I get a dialog box to fully display before executing any code. There is no user interaction, but I display messages during the execution, but they never are seen since the box does not finish displaying until the code is finished.
Do all your work in the OnShown method of your main form (which happens after the form is, well, shown). The next step would be to take Luc's advice and port your initialization code to a separate thread which could be called from the construtor or the OnLoad event.
Sounds like somebody's got a case of the Mondays -Jeff
-
Hi, the code you put in the form's constructor, or in its Load handler, will execute before the form is visible. And any code you put in any of its event handlers will run on the main or "GUI thread" at the expense of a good user interaction. If you have a lenghty operation, you really should use one (or more) separate threads, either simply instances of Thread, or members of ThreadPool, or a BackgroundWorker. That way the long operation is handled independent of the user interaction, so the form would continue to respond to moves, resizes, repaints, etc. If the long operation needs to start all by itself, launch the thread(s) from inside the form's Load handler. If it should be launched by say a button click, you obviously would put the thread launch code in the Button's Click handler. Warning: as soon as you start using separate threads you will need Control.InvokeRequired and Control.Invoke() to allow such threads to access the Form or its Controls, because only one thread is allowed to directly access Controls (the thread that created them). There are plenty of examples of this, at CodeProject and everywhere else. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
This always happens - I start a reply, get distracted, finish it, and look like I replied when I had nothing to add... :)
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
This always happens - I start a reply, get distracted, finish it, and look like I replied when I had nothing to add... :)
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
"second that" is fine too ;P
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
-
Do all your work in the OnShown method of your main form (which happens after the form is, well, shown). The next step would be to take Luc's advice and port your initialization code to a separate thread which could be called from the construtor or the OnLoad event.
Sounds like somebody's got a case of the Mondays -Jeff