Sleep - Allow Other Processes to Continue - June 1999

It is sometimes useful to put your application to 'sleep' and allow other processes to continue. In the past we would enter a 'delay loop' which would wait for some period of time. That technique does not work well because the application still continues to use system resources. A Windows 'Sleep' API suspends execution for the number of milliseconds requested. I wrote two functions [GoSleep and GoSleepEx] that convert seconds to milliseconds then call the 'Sleep' API.

The Demo Program

I wrote a VB6 demo program to illustrate the use of the functions. Enter the number of seconds the process is to 'sleep' then click the 'GoSleepEx' command button.

sleep.gif (1443 bytes)

modSleep.bas Functions

To use the functions add file modSleep.bas to your project. Functions found in modSleep.bas include:

Function Sample Description
GoSleep GoSleep 5 Sleep for five seconds. Pass a long [long integer variable]. This was my original function.
GoSleepEx GoSleepEx .25 Sleep for 1/4 second. Pass a single [single-precision floating point variable]. I added this function to allow a fraction of a second to be passed to the sleep routines.

Download VB Code

Click here to download the VB 6 Source Code [5k]. The demo is written in VB6 but the functions will work with VB4 [32-bit] and VB5.

Previous Tip   Tip Index   Next Tip

Home

Updated 2002/04/29