public void initial_state_is_signaled() { using (var e = new AutoResetEventSlim()) { Assert.True(e.Wait(0)); } }
public void wait_observes_cancellation_token() { using (var source = new CancellationTokenSource()) using (var e = new AutoResetEventSlim()) { source.Cancel(); Assert.Throws<OperationCanceledException>(() => e.Wait(source.Token)); } }
public void subsequent_waits_are_automatially_blocked_until_set() { using (var e = new AutoResetEventSlim()) { Assert.True(e.Wait(0)); Assert.False(e.Wait(0)); Assert.False(e.Wait(0)); e.Set(); Assert.True(e.Wait(0)); } }
public void wait_blocks_thread_for_specified_timeout_if_not_released() { using (var e = new AutoResetEventSlim()) { var sw = Stopwatch.StartNew(); e.Wait(0); sw.Stop(); Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(2)); sw.Restart(); e.Wait(100); sw.Stop(); Assert.InRange(sw.Elapsed, TimeSpan.FromMilliseconds(80), TimeSpan.FromMilliseconds(140)); } }