sleep vs pause

Posted by Patrick Tingen on 18-Dec-2017 04:44

In the application I am working on, I come across the use of the (external) sleep function a lot. 

PROCEDURE Sleep EXTERNAL "kernel32.DLL":
  DEFINE INPUT PARAMETER intMilliseconds AS LONG.
END PROCEDURE.

Both sleep and pause do not seem to burden the cpu so would there be any advantage in using sleep over a normal pause statement? 

All Replies

Posted by James Palmer on 18-Dec-2017 04:49

Isn't pause limited to a granularity of 1 second, whereas sleep seems to accept a granularity of a millisecond...

Posted by AdrianJones on 18-Dec-2017 05:01

nb. PAUSE is now down to millisecond. not sure when it came in. some time in the 11.* i believe

Posted by James Palmer on 18-Dec-2017 05:47

Thanks Adrian. I'm still on 10.2 and missed that little nugget.

Posted by tbergman on 18-Dec-2017 05:54

Aside from the sub second possibility, which is likely why it was implemented in the first place, using sleep does not clear the keyboard buffer in the ABL, a sometimes unfortunate side effect of pause.
 

Posted by Patrick Tingen on 18-Dec-2017 05:56

Where it is used currently, it uses sub-second pauses nor keyboard clearing, so there does not seem to be a clear reason to use it.

Posted by George Potemkin on 18-Dec-2017 06:10

> PAUSE is now down to millisecond. not sure when it came in. some time in the 11.* i believe

Since V11.6

Posted by keithg on 18-Dec-2017 07:02

Not long ago I found that in a 9.1E Windows GUI system we are supporting that the PAUSE statement was not really pausing.  The SLEEP API call did the trick.  (We needed the slight processing delay to ensure a label had enough time to be handled by the printer before the next one was sent.)

Posted by ChUIMonster on 18-Dec-2017 14:43

This may, or may not be what you're seeing in that old 9.1e code -- I've run across old code that mistakenly thought PAUSE took fractional seconds.  In that sort of code  "PAUSE 0.5." seems to "work" because 0.5 gets rounded to 1.  0.25 gets rounded to zero and thus PAUSE seems broken.  The coders probably thought it was working because the compiler didn't object to the decimal.

Posted by Rob Fitzpatrick on 19-Dec-2017 12:39

> > PAUSE is now down to millisecond. not sure when it came in. some time in the 11.* i believe

> Since V11.6

From the 11.2 NeRF:

Support for fractional time-out values

The AVM is extended to support fractional values in various ABL statements that include a pause or time-out option. Previously, the AVM only supported whole numbers and rounded fractional values to the nearest second. The statements that allow fractional time-out values, expressed as decimals, are CHOOSE, PAUSE, READKEY and WAIT-FOR.

From 11.2 ABL Ref:

...

n:

A numeric expression specifying the number of seconds that you want to suspend processing. You can choose a whole or a fractional value for the time-out interval. If the time-out period you specify is a fractional value, the value is rounded to the nearest whole millisecond.

This thread is closed