views:

31

answers:

2

Hi

I want to show processing image in form when my main form is working.

I have created processing 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??

A: 

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.

Svisstack
A: 

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.

ChrisF
That won't work either, for the same reason the OP's ProcessingForm doesn't work. No Tick events when the UI thread doesn't pump the message loop.
Hans Passant