The wait function
The wait function accepts one or more parameters as described below, and waits
(i.e. suspends execution of the program) until signalled to return, or until a timeout
This function was implemented to make it easy to write well-behaved services (i.e. services
that stop running when requested to do so).
The stopserviceevent function returns a handle to a
synchronization object that will signal when the program (if it is a service)
is requested to stop running.
- The first parameter is an expression of
integral type, which specifies the timeout period in
milliseconds. If the value of the first parameter is zero then the wait function
doesn't actually wait, instead it just checks whether it has been signaled to return. If the
value of the first argument is equal to the built-in contant
maxword then the timout interval is infinite, and the
wait function will wait indefinitely until signalled to return.
- The other parameters, if supplied, are expressions
of integral type, which specify handles to
synchronization objects. The wait function will wait until one
of the synchronization objects signals it to return, or until the timeout
interval expires. The wait function returns the handle to the
synchronization object that signaled it, or zero if the timeout period expires
before it was signalled to return.
The authoritative source of information about synchronization objects is the
Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website
For example, the following procedure was taken from the WinServS sample program and uses
the wait function to stop running when requested to do so.
ProgramState is a global variable used as a flag to signal when the program is
stopping (i.e. being shut down) to prevent recursive calls to the
ServerShutDown procedure. The ServerShutDown procedure shuts
down the program.
if (ProgramState<>Stopping) and (StopServiceEvent<>0) then
if wait(WAIT_INTERVAL, StopServiceEvent)=StopServiceEvent then
ProgramState := Stopping;
Operating Systems: All
Standard Pascal: No