If I use WinAPI SLEEP() instead of loops and messagebox timeouts, how do I detect and respond to an escape of abort button click?
I need an infinite loop timer, but I want to be able to close or cancel the program...
TIA
I notice that nobody has replied, much to my surprise. What I do in similar situations, is to look for a specific file inside the loop. If the file exists, I delete it and exit from the loop.
This gives me the option of forcing an exit from the loop in several ways. I can have a On Escape or a On Key Label create the file before the loop starts. I can have an icon on my desktop which creates the file via a simple batch file. Or another program can create the file.
Michael,
I tend to use Sleep()
in combination with a loop and DoEvents
if I need to wait for some UI action. Short sleep cycles
*** Set this to .t. somewhere
PUBLIC plExit
plExit = .f.
DO WHILE .T.
Sleep(100)
DOEVENTS && if you need other UI interaction
IF plExit
EXIT
ENDIF
ENDDO
You can use ON KEY ALT-X plExit = .t.
or something like that to trigger the exit.
If you need to wait for a specific length of time, use a for loop and account for the sleep timeout in your loop counter:
*** wait 5 seconds
FOR lnX = 1 to 50
Sleep(100)
DOEVENTS && if you need other UI interaction
ENDFOR
The reason for all this is that if you Sleep()
you tie up FoxPro's UI thread and nothing updates. if you do that too long the app will white screen so generally I always use the above approach to keep the UI still responsive - ie. you can move the window around, resize etc.
+++ Rick ---