FoxPro Programming
Exiting out of SLEEP()
Gravatar is a globally recognized avatar based on your email address. Exiting out of SLEEP()
  Michael Hogan (Ideate Hosting)
  All
  Apr 28, 2017 @ 07:09pm

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

Gravatar is a globally recognized avatar based on your email address. re: Exiting out of SLEEP()
  Tore Bleken
  Michael Hogan (Ideate Hosting)
  Apr 29, 2017 @ 07:24am

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.

Gravatar is a globally recognized avatar based on your email address. re: Exiting out of SLEEP()
  Rick Strahl
  Michael Hogan (Ideate Hosting)
  Apr 29, 2017 @ 10:20am

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 ---

Gravatar is a globally recognized avatar based on your email address. re: Exiting out of SLEEP()
  Michael Hogan (Ideate Hosting)
  Rick Strahl
  Apr 30, 2017 @ 09:46am

Perfect - thanks, Rick. You've saved me lots of trial and error... again!

© 1996-2017