public void Signal_signal_then_wait_wait_wait()
        {
            MonitorSemaphore monitor = new MonitorSemaphore();

            monitor.Signal();
            monitor.Signal();
            var timeout = monitor.Wait(TimeSpan.FromSeconds(1));

            Assert.IsTrue(timeout, "timeout 1 should not have occurred");

            timeout = monitor.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(timeout, "timeout 2 should not have occurred");

            timeout = monitor.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(timeout, "timeout 3 should have occurred");
        }
        public void Wait_then_timeout()
        {
            MonitorSemaphore monitor = new MonitorSemaphore();
            var timeout = monitor.Wait(TimeSpan.FromSeconds(0.1));

            Assert.IsFalse(timeout, "timeout should have occurred");
        }
        public void Wait_then_Signal()
        {
            MonitorSemaphore monitor = new MonitorSemaphore();

            new Thread(() => {
                Thread.Sleep(100);
                monitor.Signal();
            }).Start();
            var timeout = monitor.Wait(TimeSpan.FromSeconds(3));

            Assert.IsTrue(timeout, "timeout should not have occurred");
        }
Beispiel #4
0
 /// <summary>
 /// Waits for event to be signaled.
 /// </summary>
 /// <param name="monitor">Event to wait on.</param>
 /// <param name="timeout">Timeout period. Use <cref see="TimeSpan"/>.MaxValue for no timeout.</param>
 /// <returns>Returns true if the event was signaled before the timeout, false otherwise.</returns>
 public static bool WaitFor(MonitorSemaphore monitor, TimeSpan timeout)
 {
     DispatchThreadEvictWorkItems();
     return(monitor.Wait(timeout));
 }