The problem I've noticed is if a sub with DoEvents is running and you click and hold on the top of the application window like you would if you want to move the form to the other side of the screen, the application stops and hangs until you release it. It does the same thing if you click and hold on the forms min/max buttons. I assume that this is because the event triggered hasn't completed yet so I haven't returned back from DoEvents.

So in my example below, if you run this and click and hold the form and drag it around the screen, you will notice that the "counter" stops until you release the form. Any ideas how to get around this to keep my program from hanging?


Code:
Dim stoprequest As Boolean


Private Sub Command1_Click()
Dim counter As Long

stoprequest = False
While stoprequest = False
DoEvents
counter = counter + 1
Label1.Caption = counter
Wend

End Sub

Private Sub Command2_Click()
stoprequest = True
End Sub

Private Sub Form_Load()
stoprequest = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
End
End Sub