views:

71

answers:

3

I have multiple forms that popup during an intensive operation. For example, when a form popups asking user for something, and the user clicks OK, the form's graphics stay on the main screen, even though it is closed. How can I make it so that these graphics disappear completely?

+4  A: 

I would recommend performing the heavy work in the background (using a BackgroundWorker for instance), so that the GUI thread is not blocked. That way, the forms will be able to peform screen updates while the work is going on.

Fredrik Mörk
I moved the operations to a thread and now the GUI refreshes perfectly. Thank you!
sbenderli
+1  A: 

You can call the Refresh() method on the main screen form, which will force a graphics repaint.

JustLoren
+4  A: 

It sounds like perhaps you are doing intensive processing on your main thread, which is the thread that processes events like painting windows. Instead you should spawn a separate thread for doing your computations/tasks so that your main thread can continue.

Alternatively you can call DoEvents() periodically while doing your processing to allow the form to refresh, but using DoEvents is kind of a cludge in my opinion.

AaronLS