示例#1
0
 /// <summary>释放对象上的锁并阻止当前线程,直到它重新获取该锁。如果已用指定的超时时间间隔,则线程进入就绪队列。可以在等待之前退出同步上下文的同步域,随后重新获取该域。</summary>
 /// <returns>如果在指定的时间过期之前重新获取该锁,则为 true;如果在指定的时间过期之后重新获取该锁,则为 false。此方法只有在重新获取该锁后才会返回。</returns>
 /// <param name="obj">要在其上等待的对象。</param>
 /// <param name="timeout">
 /// <see cref="T:System.TimeSpan" />,表示线程进入就绪队列之前等待的时间量。</param>
 /// <param name="exitContext">如果在等待前退出并重新获取上下文的同步域(如果在同步上下文中),则为 true;否则为 false。</param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="obj" /> 参数为 null。</exception>
 /// <exception cref="T:System.Threading.SynchronizationLockException">不是从同步的代码块内调用 Wait。</exception>
 /// <exception cref="T:System.Threading.ThreadInterruptedException">调用 Wait 的线程稍后从等待状态中断。当另一个线程调用此线程的 <see cref="M:System.Threading.Thread.Interrupt" /> 方法时会发生这种情况。</exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// <paramref name="timeout" /> 参数为负且不表示 <see cref="F:System.Threading.Timeout.Infinite" />(-1 毫秒),或者大于 <see cref="F:System.Int32.MaxValue" />。</exception>
 /// <filterpriority>1</filterpriority>
 public static bool Wait(object obj, TimeSpan timeout, bool exitContext)
 {
     return(Monitor.Wait(obj, Monitor.MillisecondsTimeoutFromTimeSpan(timeout), exitContext));
 }
示例#2
0
 public static bool Wait(object obj, TimeSpan timeout)
 {
     return(Monitor.Wait(obj, Monitor.MillisecondsTimeoutFromTimeSpan(timeout), false));
 }
示例#3
0
 public static bool TryEnter(object obj, TimeSpan timeout)
 {
     return(Monitor.TryEnter(obj, Monitor.MillisecondsTimeoutFromTimeSpan(timeout)));
 }