public static bool SignalAndWait (WaitHandle toSignal, WaitHandle toWaitOn, int millisecondsTimeout, bool exitContext) { if (toSignal == null) { throw new ArgumentNullException ("toSignal"); } if (toWaitOn == null) { throw new ArgumentNullException ("toWaitOn"); } if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException ("millisecondsTimeout"); } toSignal.CheckDisposed (); toWaitOn.CheckDisposed (); var tos = toSignal.waitable; var tow = toWaitOn.waitable; if (tos == null || tow == null) { return false; } try { if (exitContext) { SynchronizationAttribute.ExitContext (); } return StWaitable.SignalAndWait (tos, tow, new StCancelArgs (millisecondsTimeout, true)); } finally { if (exitContext) { SynchronizationAttribute.EnterContext (); } } }