This documentation is archived and is not being maintained.

WaitHandle.SignalAndWait Method (WaitHandle, WaitHandle, Int32, Boolean)

Note: This method is new in the .NET Framework version 2.0.

Signals one WaitHandle and waits on another, as an atomic operation, specifying a time-out interval as a 32-bit signed integer and specifying whether to exit the synchronization domain for the context before entering the wait.

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

public static bool SignalAndWait (
	WaitHandle toSignal,
	WaitHandle toWaitOn,
	int millisecondsTimeout,
	bool exitContext
)
public static boolean SignalAndWait (
	WaitHandle toSignal, 
	WaitHandle toWaitOn, 
	int millisecondsTimeout, 
	boolean exitContext
)
public static function SignalAndWait (
	toSignal : WaitHandle, 
	toWaitOn : WaitHandle, 
	millisecondsTimeout : int, 
	exitContext : boolean
) : boolean

Parameters

toSignal

The WaitHandle to signal.

toWaitOn

The WaitHandle to wait on.

millisecondsTimeout

An integer that represents the interval to wait. If the value is Timeout.Infinite, that is, -1, the wait is infinite.

exitContext

true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false.

Return Value

true if both the signal and the wait completed successfully, or false if the signal completed but the wait timed out.

Exception typeCondition

ArgumentNullException

toSignal is a null reference (Nothing in Visual Basic).

-or-

toWaitOn is a null reference (Nothing in Visual Basic).

NotSupportedException

The method is called on a thread that has STAThreadAttribute.

PlatformNotSupportedException

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

SemaphoreFullException

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

ArgumentOutOfRangeException

millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.

AbandonedMutexException

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

The exitContext parameter has no effect unless the SignalAndWait method is called from inside a nondefault managed context. This can happen if your thread is inside a call to an instance of a class derived from ContextBoundObject. Even if you are currently executing a method on a class that does not derive from ContextBoundObject, like String, you can be in a nondefault context if a ContextBoundObject is on your stack in the current application domain.

When your code is executing in a nondefault context, specifying true for exitContext causes the thread to exit the nondefault managed context (that is, to transition to the default context) before executing the SignalAndWait method. The thread returns to the original nondefault context after the call to the SignalAndWait method completes.

This can be useful when the context-bound class has SynchronizationAttribute. In that case, all calls to members of the class are automatically synchronized, and the synchronization domain is the entire body of code for the class. If code in the call stack of a member calls the SignalAndWait method and specifies true for exitContext, the thread exits the synchronization domain, allowing a thread that is blocked on a call to any member of the object to proceed. When the SignalAndWait method returns, the thread that made the call must wait to reenter the synchronization domain.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Show: