Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter FourFlow Control (continued)

WaitForObject Function

Overview

The WaitForObject function will wait for a specified object to be in a signaled state (ended) or until an optional time out occurs. This function can be used to synchronize multi-process and multi-thread programs and scripts.

Syntax/Parameters

Syntax

int = WaitForObject ( handle hObject, [int ms] );

Parameters

hObject

A handle to a compatible object.

ms

An optional int that specifies the amount of time in milliseconds to wait for the object. If no time is specified, the function will wait indefinitely. A value of 0 will test the object and quickly exit.

Return Value

Returns an int as ERROR_NONE on a successful signaled state or a formatted error code on failure. The lower portion of the formatted error code will contain a Windows error code or commonly WAIT_TIMEOUT (0x0102) if the time-out period has elapsed.

Remarks

This function can only be used with objects that support signaling, for example, processes created with the CreateProcess or RunBackgroundScript functions. Use of incompatible objects will result in an immediate return with ERROR_INVALID_HANDLE (6) ORed with ERROR_SOFT (0x80000000).

The WaitForObject function checks the current state of the specified object. If the object’s state is nonsignaled, the calling thread enters the wait state until the object becomes signaled or the time-out interval elapses.

The function modifies the state of some types of synchronization objects. Modification occurs only for the object whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one.

The WaitForObject function can wait for the following objects (only some objects can be directly created in Legato):

•  Change notification

•  Console input

•  Event

•  Memory resource notification

•  Mutex

•  Process

•  Semaphore

•  Thread

•  Waitable timer

Use caution when calling the wait functions and code that directly or indirectly creates windows. If a thread creates any windows, it must process those windows’ messages. Message broadcasts are sent to all windows in the system. A thread that uses a wait function with a no time-out interval may cause the system to become deadlocked.

Use caution if the wait is run in the primary process thread since it will stop the application’s message loop and the application may appear unresponsive.

The ms value does not include time spent in low-power states. For example, the time-out will not keep counting down while the computer is asleep. See MSDN for more information.

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Legato IDE, Legato Basic