The wait function

Description

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 period expires.

Parameters

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 authoritative source of information about synchronization objects is the Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website at msdn.microsoft.com.

Example

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.

 procedure CheckForStopServiceEvent;
 const
  WAIT_INTERVAL=0;
 begin
  if (ProgramState<>Stopping) and (StopServiceEvent<>0) then
   begin
    //LogMessage('Calling wait');
    if wait(WAIT_INTERVAL, StopServiceEvent)=StopServiceEvent then
     begin
      ProgramState := Stopping;
      ServerShutDown;
     end;
   end
 end;

Portability

Operating Systems: All
Standard Pascal: No