views:

49

answers:

1

On a regular basis I find myself writing little utility programs that use some loop which takes a while to process. Yet while the loop is going the form no longer refreshes so if you were to move the form, or move another window over it and off, the form would be blank until the loop finishes.

Now I know the correct way to deal with this is to use a background working to do the time consuming task on a separate thread. But I haven't quite got my head around the multi threaded stuff just yet.

So If I'm only going to use one thread what is the best thing to do on each loop to keep the contents of the form up to date. For example there may be a progress bar in the form.

I've seen and used various combonations of Form.Refresh(), Form.Update(), and Application.DoEvents() but was wondering what is the best way to deal with this?

+4  A: 

You can fake it with Application.DoEvents() at different locations in the code, but you really should put the work in another thread.

Randolph Potter
Agreed. `DoEvents` can have tricky side effects.
Henk Holterman