Zzzzzzz. . . .Suspending a Thread

Dear Dr. GUI:

This problem has puzzled me for over a year. Do you know how to implement a "SLEEP" function in Visual Basic that puts the program on hold, while other programs continue to run (while preventing the held program from getting new events)?

It would be extra cool if when sleep is over (or when the "WAKE UP" function is called), the missed events get executed.

How about using a message hook (like Message Blaster)? How would I store messages to be sent later?

Andy Rosa

Dr. GUI replies:

OOOOH! You are soooo close. The function you want is . . . Sleep(), which is from the Windows API.

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

This function suspends execution of your thread for a specified number of milliseconds. Messages sent to your application are still queued up, and you get them as soon as you wake up. If you want a wake-up call, just put in a call to your wake-up function right after the Sleep() call.

Private Sub Command1_Click()

Sleep(10000)

ret = MsgBox("Time to wake up!", vbInformation)

End Sub

Dr. GUI hastens to point out that the WakeUpCall() function exported from NIGHTCLERK.DLL is unreliable and so should never be used.