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

Parameters

toSignal
Type: System.Threading.WaitHandle

The WaitHandle to signal.

toWaitOn
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
ArgumentNullException

toSignal is null.

-or-

toWaitOn is null.

NotSupportedException

The method was called on a thread that has STAThreadAttribute.

PlatformNotSupportedException

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

InvalidOperationException

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

AbandonedMutexException

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
Show: