I've observed with c++/non VB apps that when they are doing some CPU intensive work they run quite fast and still respond to user events like mouse-click, keypress etc.
Obviously they are not using any thing like the DoEvents of VB which processes the system message queue. Instead they seem to be giving time to only their own events.

In VB, the only way I know to let your app respond to events is to put a DoEvents in your procedure/loop.

Let's take a very simple example:
VB Code:
  1. Option Explicit
  2. Dim bCancel As Boolean
  3.  
  4. Private Sub cmdCancel_Click()
  5.     If vbYes = MsgBox("Cancel Processing?", vbYesNo + vbQuestion) Then
  6.         bCancel = True
  7.     End If
  8. End Sub
  9.  
  10. Private Sub cmdOK_Click()
  11.     bCancel = False
  12.     Do
  13.         If bCancel Then Exit Do
  14.         DoSomething
  15.         DoEvents
  16.     Loop
  17.     MsgBox "OK", vbInformation
  18. End Sub
  19.  
  20. Private Sub DoSomething()
  21.     'Add code to do something here
  22. End Sub

This code would work fine, but it is very slow. But if you comment out the Doevents, it would go very fast as it won't process the system message queue. But then it won't respond to cmdCancel_Click and you would ultimately have to End task teh application.
I was looking for some replacement for the DoEvents which won't process the entire system message queue, instead give time to my application only.


Pradeep