How to show processing form in my main form
I want to show processing image in form when my main form is working.
I have created processi开发者_JS百科ng form .
I tried it with
ProcessingForm obj = new ProcessingForm();
obj.show();
DOSomeStuff();
obj.close();
it shows processing form..but some time it becomes not responding...or my gif image stops animating.
How to do that??
You can use BackgroundWorker
class to separate process working under Form Messages processing and Processing your code like DoSomeStuff()
. If you want know what progress of your DoSomeStuff()
was done, you can implemend in your background worker this because this class support it.
But if your enviroment is to slow to getting this 2 things processing in realtime, you must give your BackgroundWorker some lowest priority then your image can be working in realtime but your stuff doing longer. This is not good solution because depends on enviromen.
I've used this code from CodeProject. It's a "rotating" timer animation similar to that used by Firefox.
Add the dll as a reference to your project and drop the progress indicator on your form.
Set it's initial state to be invisible.
Then when you want to show your processing call:
this.progressIndicator.Visible = true;
this.progressIndicator.Start();
To remove it when the processing is complete call:
this.progressIndicator.Stop();
this.progressIndicator.Visible = false;
It uses a System.Windows.Forms.Timer
to control the animation and overrides the OnPaint
method to draw the image rotating. This is probably as accurate as you would need.
I'm not the author, but I have used this and not had any problems with it slowing the actual processes down appreciably.
However, you will have to put your processing onto another thread - use the BackgroundWorker
class, otherwise the UI won't update.
精彩评论