Cancelling a long running process in VB6.0 without DoEvents?

vb6

Solution

Nope, you got it right, you definitely want DoEvents in your loop.

If you put the `DoEvents` in your main loop and find that slows down processing too much, try calling the Windows API function `GetQueueStatus` (which is much faster than DoEvents) to quickly determine if it's even necessary to call DoEvents. `GetQueueStatus` tells you if there are any events to process.

' at the top:
Declare Function GetQueueStatus Lib "user32" (ByVal qsFlags As Long) As Long

' then call this instead of DoEvents:
Sub DoEventsIfNecessary()
    If GetQueueStatus(255) <> 0 Then DoEvents
End Sub

Problem

Is it possible to cancel out of a long running process in VB6.0 without using DoEvents? For example: ``` for i = 1 to someVeryHighNumber ' Do some work here ' ... if cancel then exit for end if next Sub btnCancel_Click() cancel = true End Sub ``` I assume I need a "DoEvents" before the "if cancel then..." is there a better way? It's been awhile...

Original source

Related problems