System.Windows.Forms.Application.DoEvents Method

Processes all Windows messages currently in the message queue.

Syntax

public static void DoEvents ()

Remarks

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 Application.DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a System.Windows.Forms.ListBox and add Application.DoEvents to your code, your form repaints when another window is dragged over it. If you remove Application.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.

Unlike Visual Basic 6.0, the Application.DoEvents method does not call the System.Threading.Thread.Sleep(int) method.

Typically, you use this method in a loop to process messages.

Note:

Calling this method causes the current thread to be suspended while all waiting window messages are processed. If a message causes an event to be triggered, then other areas of your application code may execute. This can cause your application to exhibit unexpected behaviors that are difficult to debug. If you perform operations or computations that take a long time, it is often preferable to perform those operations on a new thread. For more information about asynchronous programming, see Asynchronous Programming Overview.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0