System.Threading.WaitHandle Class

public abstract class WaitHandle : MarshalByRefObject, IDisposable

Base Types

Object
  MarshalByRefObject
    WaitHandle

This type implements IDisposable.

Assembly

mscorlib

Library

BCL

Summary

Encapsulates operating-system specific objects that wait for exclusive access to shared resources.

Description

[Note: This class is typically used as a base class for synchronization objects. Classes derived from WaitHandle define a signaling mechanism to indicate taking or releasing exclusive access to a shared resource, but use the inherited WaitHandle methods to block while waiting for access to shared resources.

The static methods of this class are used to block a Thread until one or more synchronization objects receive a signal.

]

See Also

System.Threading Namespace

Members

WaitHandle Constructors

WaitHandle Constructor

WaitHandle Methods

WaitHandle.Close Method
WaitHandle.Dispose Method
WaitHandle.Finalize Method
WaitHandle.System.IDisposable.Dispose Method
WaitHandle.WaitAll Method
WaitHandle.WaitAny Method
WaitHandle.WaitOne Method


WaitHandle Constructor

public WaitHandle();

Summary

Constructs and initializes a new instance of the WaitHandle class.

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.Close Method

public virtual void Close();

Summary

Releases all resources held by the current instance.

Description

This method is the public version of the System.IDisposable.Dispose method implemented to support the IDisposable interface.

[Behaviors: This method releases any unmanaged resources held by the current instance. This method can, but is not required to, suppress finalization during garbage collection by calling the System.GC.SuppressFinalize(System.Object) method. ]

[Default: As described above.]

[Overrides: Override this property to release resources allocated in subclasses. ]

[Usage: Use this method to release all resources held by an instance of WaitHandle . Once this method is called, references to the current instance cause undefined behavior. ]

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.Dispose Method

protected virtual void Dispose(bool explicitDisposing);

Summary

Releases the unmanaged resources used by the WaitHandle and optionally releases the managed resources.

Parameters

explicitDisposing
true to release both managed and unmanaged resources; false to release only unmanaged resources.

Description

[Behaviors: This method releases all unmanaged resources held by the current instance. When the explicitDisposing parameter is true , this method releases all resources held by any managed objects referenced by the current instance. This method invokes the Dispose() method of each referenced object.]

[Overrides: Override this method to dispose of resources allocated by types derived from WaitHandle. When overriding Dispose (Boolean), be careful not to reference objects that have been previously disposed in an earlier call to Dispose or Close . Dispose can be called multiple times by other objects. ]

[Usage: This method is called by the public System.Threading.WaitHandle.Dispose(System.Boolean) method and the System.Object.Finalize method. Dispose() invokes this method with the explicitDisposing parameter set to true . System.Object.Finalize invokes Dispose with explicitDisposing set to false .]

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.Finalize Method

~WaitHandle();

Summary

Releases the resources held by the current instance.

Description

[Note: Application code does not call this method; it is automatically invoked during garbage collection unless finalization by the garbage collector has been disabled. For more information, see System.GC.SuppressFinalize(System.Object), and System.Object.Finalize.

This method overrides System.Object.Finalize.

]

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.System.IDisposable.Dispose Method

void IDisposable.Dispose();

Summary

Implemented to support the IDisposable interface. [Note: For more information, see System.IDisposable.Dispose.]

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.WaitAll Method

public static bool WaitAll(WaitHandle[] waitHandles);

Summary

Waits for all of the elements in the specified array to receive a signal.

Parameters

waitHandles
A WaitHandle array containing the objects for which the current instance will wait. This array cannot contain multiple references to the same object (duplicates).

Return Value

Returns true when every element in waitHandles has received a signal. If the current thread receives a request to abort before the signals are received, this method returns false .

Exceptions

Exception TypeCondition
ArgumentNullExceptionwaitHandles is null or one or more elements in the waitHandles array is null .
DuplicateWaitObjectExceptionwaitHandles contains elements that are duplicates.
NotSupportedExceptionThe number of objects in waitHandles is greater than the system permits.

Description

The maximum number of objects specified in the waitHandles array is system defined.

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.WaitAny Method

public static int WaitAny(WaitHandle[] waitHandles);

Summary

Waits for any of the elements in the specified array to receive a signal.

Parameters

waitHandles
A WaitHandle array containing the objects for which the current instance will wait. This array cannot contain multiple references to the same object (duplicates).

Return Value

Returns a Int32 set to the index of the element in waitHandles that received a signal.

Exceptions

Exception TypeCondition
ArgumentNullExceptionwaitHandles is null or one or more elements in the waitHandles array is null .
DuplicateWaitObjectExceptionwaitHandles contains elements that are duplicates.
NotSupportedExceptionThe number of objects in waitHandles is greater than the system permits.

Description

The maximum number of objects specified in the waitHandles array is system defined.

See Also

System.Threading.WaitHandle Class, System.Threading Namespace

WaitHandle.WaitOne Method

public virtual bool WaitOne();

Summary

Blocks the current thread until the current instance receives a signal.

Return Value

Returns true when the current instance receives a signal.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current instance has already been disposed.

Description

[Behaviors: The caller of this method blocks indefinitely until a signal is received by the current instance. ]

[Overrides: Override this method to customize the behavior of types derived from WaitHandle .]

[Usage: Use this method to block until a WaitHandle receives a signal from another thread, such as is generated when an asynchronous operation completes. For more information, see the IAsyncResult interface.]

See Also

System.Threading.WaitHandle Class, System.Threading Namespace