This bit of code illustrates why using .DoEvents may produce undesired results. In this example the .DoEvents is used to update the textbox.
Run the code and press enter. Wait for the count to reach 10,000. Press enter again to clear the count.
Then press enter several times quickly. The count is not likely to be 10,000.
Public Class Form1
'requires two buttons and a textbox
Const tries As Integer = 10000
Dim counter As Integer
Private Sub Button1_Click(sender As System.Object, _
e As System.EventArgs) Handles Button1.Click
Button2.Select()
For x As Integer = 1 To tries
counter += 1
TextBox1.Text = counter.ToString("n0")
Application.DoEvents() 'used to update UI :( TextBox1.Refresh would be better
Next
End Sub
Private Sub Button2_Click(sender As System.Object, _
e As System.EventArgs) Handles Button2.Click
'reset counter
counter = 0
TextBox1.Text = ""
Button1.Select()
End Sub
Private Sub Form1_Shown(sender As Object, _
e As System.EventArgs) Handles Me.Shown
Button1.Select()
End Sub
End Class