ClassSystem.Windows.Forms.Application SyntaxApplication.DoEvents( ) DescriptionThe DoEvents method allows the application to process events and messages waiting in its message queue. Some processor-intensive activities in your application may prevent user-related input and output events from occurring in a timely manner. The DoEvents method processes pending events. Usage at a Glance
ExampleThe following example demonstrates the usefulness of the DoEvents method. When the GetBusy command button is clicked, it begins a very busy and infinite process. Normally, clicks on the TakeABreak command button would be blocked by the activity, but the DoEvents method makes its use possible. ' ----- Assumes a form with two buttons, GetBusy and TakeABreak. Private iterationsSoFar As Long Private interruptFlag As Boolean Private Sub GetBusy_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles GetBusy.Click interruptFlag = False Do While (interruptFlag = False) iterationsSoFar += 1 DoEvents( ) Loop MsgBox("Loop interrupted after " & iterationsSoFar & _ " iterations.") End Sub Private Sub TakeABreak_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles TakeABreak.Click ' ----- Stop the work. interruptFlag = True End Sub Version DifferencesVisual Basic 2005 adds an equivalent My.Application.DoEvents method. See AlsoApplication Class |