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
2010-06-16 13:34:46
I moved the operations to a thread and now the GUI refreshes perfectly. Thank you!
sbenderli
2010-06-16 14:17:17
+1
A:
You can call the Refresh() method on the main screen form, which will force a graphics repaint.
JustLoren
2010-06-16 13:36:30
+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
2010-06-16 13:37:01