Thursday, January 8, 2009

Freezing / refreshing problem

Very often happend your form is not refreshing correctly or freezing.
Another time during processing one task you wanted perform another.

Common knowledge is start using (multi) Threading future in C#

In some (simple) scenarios you can take into consideartion another command:

Application.DoEvents()


Microsoft explains it as:

"When you run a Windows Form, it creates the new form, which then waits for events to handle. Each time the form handles an event, it processes all the code associated with that event. All other events wait in the queue. While your code handles the event, your application does not respond. For example, the window does not repaint if another window is dragged on top. 

If you call DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a ListBox and add DoEvents to your code, your form repaints when another window is dragged over it. If you remove DoEvents from your code, your form will not repaint until the click event handler of the button is finished executing. For more information on messaging, see User Input in Windows Forms."

http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home