WaitForSingleObject Function

Action

Waits until the specified object is in the signaled state or until the time-out interval elapses.

Include file

Kernel.bdh

Syntax

WaitForSingleObject( in hHandle    : number,
                     in nTimeoutMs : number ): number;

Return value

  • WAIT_ABANDONED. The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.

  • WAIT_OBJECT_0. The state of the specified object is signaled.

  • WAIT_TIMEOUT. The time-out interval has elapsed and the object's state is nonsignaled.

Parameter Description
hHandle Handle of the object
nTimeoutMs

Specifies the time-out interval, in milliseconds

  • 0 = test object's state and return immediately

  • INFINITE = Time out interval never elapses

Example

dcltrans
  transaction TCloseHandle
  var
    hMutex: number;
  begin
    hMutex := CreateMutex("MutexObject");
    write("mutex object created"); writeln;
    WaitForSingleObject(hMutex, INFINITE);
    ReleaseMutex(hMutex);
    write("mutex object released"); writeln;
    CloseHandle(hMutex);
    write("handle to mutex object closed"); writeln;
  end TCloseHandle;

Output

mutex object created
mutex object released
handle to mutex object closed

Sample scripts

Trans.bdf, MutexLogin.bdf