Пример #1
0
        /// <summary>Signals one wait handle and waits on another, specifying the time-out interval as a <see cref="T:System.TimeSpan" /> and specifying whether to exit the synchronization domain for the context before entering the wait.</summary>
        /// <returns>true if both the signal and the wait completed successfully, or false if the signal completed but the wait timed out.</returns>
        /// <param name="toSignal">The wait handle to signal.</param>
        /// <param name="toWaitOn">The wait handle to wait on.</param>
        /// <param name="timeout">The interval to wait. If the value is -1, the wait is infinite.</param>
        /// <param name="exitContext">true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="toSignal" /> is null.-or-<paramref name="toWaitOn" /> is null. </exception>
        /// <exception cref="T:System.NotSupportedException">The method was called on a thread that has <see cref="T:System.STAThreadAttribute" />. </exception>
        /// <exception cref="T:System.PlatformNotSupportedException">This method is not supported on Windows 98 or Windows Millennium Edition.</exception>
        /// <exception cref="T:System.InvalidOperationException">
        ///   <paramref name="toSignal" /> is a semaphore, and it already has a full count. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="timeout" /> evaluates to a negative number of milliseconds other than -1. -or-<paramref name="timeout" /> is greater than <see cref="F:System.Int32.MaxValue" />.</exception>
        /// <exception cref="T:System.Threading.AbandonedMutexException">The wait completed because a thread exited without releasing a mutex. This exception is not thrown on Windows 98 or Windows Millennium Edition.</exception>
        /// <filterpriority>1</filterpriority>
        public static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn, TimeSpan timeout, bool exitContext)
        {
            double totalMilliseconds = timeout.TotalMilliseconds;

            if (totalMilliseconds > 2147483647.0)
            {
                throw new ArgumentOutOfRangeException("timeout");
            }
            return(WaitHandle.SignalAndWait(toSignal, toWaitOn, Convert.ToInt32(totalMilliseconds), false));
        }
Пример #2
0
 /// <summary>向一个 <see cref="T:System.Threading.WaitHandle" /> 发出信号并等待另一个。</summary>
 /// <returns>如果信号和等待都成功完成,则为 true;如果等待没有完成,则此方法不返回。</returns>
 /// <param name="toSignal">要发出信号的 <see cref="T:System.Threading.WaitHandle" />。</param>
 /// <param name="toWaitOn">要等待的 <see cref="T:System.Threading.WaitHandle" />。</param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="toSignal" /> is null.-or-<paramref name="toWaitOn" /> is null. </exception>
 /// <exception cref="T:System.NotSupportedException">The method was called on a thread that has <see cref="T:System.STAThreadAttribute" />. </exception>
 /// <exception cref="T:System.PlatformNotSupportedException">This method is not supported on Windows 98 or Windows Millennium Edition. </exception>
 /// <exception cref="T:System.InvalidOperationException">
 /// <paramref name="toSignal" /> is a semaphore, and it already has a full count. </exception>
 /// <exception cref="T:System.Threading.AbandonedMutexException">The wait completed because a thread exited without releasing a mutex.This exception is not thrown on Windows 98 or Windows Millennium Edition.</exception>
 /// <filterpriority>1</filterpriority>
 public static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn)
 {
     return(WaitHandle.SignalAndWait(toSignal, toWaitOn, -1, false));
 }