Esempio n. 1
0
 public static void PulseAll(object condition)
 {
     MonitorEx.EnterNonInterruptibly(condition, out var wasInterrupted);
     Monitor.PulseAll(condition);
     Monitor.Exit(condition);
     if (wasInterrupted)
     {
         Thread.CurrentThread.Interrupt();
     }
 }
Esempio n. 2
0
 public static void Wait(object mlock, object condition, TimeSpan timeout)
 {
     if (mlock == condition)
     {
         Monitor.Wait(mlock, timeout);
         return;
     }
     Monitor.Enter(condition); // can throw ThreadInterruptedException
     Monitor.Exit(mlock);
     try
     {
         Monitor.Wait(condition, timeout); // can throw ThreadInterruptedException
     }
     finally
     {
         Monitor.Exit(condition);
         MonitorEx.EnterNonInterruptibly(mlock, out var wasInterrupted);  // can throw ThreadInterruptedException
         if (wasInterrupted)
         {
             throw new ThreadInterruptedException();
         }
     }
 }