Non modal "status" form
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 wi开发者_如何学编程th 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
Yo need to run the do stuff part in a different thread.
and then all myWaitForm.Show()
Take a look at BackgroundWorker
class here
i agree on the "other thread" suggestion, but for simple and short purposes Application.DoEvents() will do.
You'd better move your "do stuff" code to other thread. and use Application.DoEvents() to proces the form messages
The term you're looking for is "splash screen".
Here are a few related comments. https://stackoverflow.com/search?q=splash+screen+c%23
精彩评论