Non modal "status" form

Posted by David Jenings on Stack Overflow See other posts from Stack Overflow or by David Jenings
Published on 2010-05-31T11:37:34Z Indexed on 2010/05/31 11:43 UTC
Read the original article Hit count: 417

Filed under:
|
|

At the beginning of a section of C# code that could take several seconds to complete, I'd like to display a non modal form with a label that just says, "Please wait..."

WaitForm myWaitForm = null;

try { // if conditions suggest process will take awhile myWaitForm = new WaitForm(); myWaitForm.Show();

// do stuff } finally { if (myWaitForm != null) { myWaitForm.Hide(); myWaitForm.Dispose(); myWaitForm = null; } }

The problem: the WaitForm doesn't completely display before the rest of the code ties up the thread. So I only see the frame of the form. In Delphi (my old stomping ground) I would call Application.ProcessMessages after the Show() Is there an equivalent in C#? Is there a canned "status" form that I can use in situations like this? Is there a better way to approach this?

Thanks in advance. David Jennings

© Stack Overflow or respective owner

Related posts about c#

Related posts about form