WaitHandle.SignalAndWait Method (WaitHandle, WaitHandle)


Signals one WaitHandle and waits on another.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

static member SignalAndWait : 
        toSignal:WaitHandle *
        toWaitOn:WaitHandle -> bool


Type: System.Threading.WaitHandle

The WaitHandle to signal.

Type: System.Threading.WaitHandle

The WaitHandle to wait on.

Return Value

Type: System.Boolean

true if both the signal and the wait complete successfully; if the wait does not complete, the method does not return.

Exception Condition

toSignal is null.


toWaitOn is null.


The method was called on a thread that has STAThreadAttribute.


This method is not supported on Windows 98 or Windows Millennium Edition.


toSignal is a semaphore, and it already has a full count.


The wait completed because a thread exited without releasing a mutex. This exception is not thrown on Windows 98 or Windows Millennium Edition.

This operation is not guaranteed to be atomic. After the current thread signals toSignal but before it waits on toWaitOn, a thread that is running on another processor might signal toWaitOn or wait on it.

The following code example uses the SignalAndWait(WaitHandle, WaitHandle) method overload to allow the main thread to signal a blocked thread and then wait until the thread finishes a task.

The example starts five threads, allows them to block on an EventWaitHandle created with the EventResetMode.AutoReset flag, and then releases one thread each time the user presses the ENTER key. The example then queues another five threads and releases them all using an EventWaitHandle created with the EventResetMode.ManualReset flag.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top