public void AtomicWaitComplete() { var counter = new AtomicWaitCounter(2); var fac = new TaskFactory(); var t1 = fac.StartNew(() => { Thread.Sleep(TimeSpan.FromMilliseconds(50)); counter.Increment(); }); var t2 = fac.StartNew(() => { Thread.Sleep(TimeSpan.FromMilliseconds(50)); counter.Increment(); }); Assert.IsTrue(counter.Completion.Wait(TimeSpan.FromMilliseconds(300))); Thread.Sleep(100); Assert.IsTrue(t1.IsCompleted); Assert.IsTrue(t2.IsCompleted); }
public void AtomicWaitTimeout() { var counter = new AtomicWaitCounter(2); var fac = new TaskFactory(); using var t1 = fac.StartNew(() => { Thread.Sleep(TimeSpan.FromMilliseconds(50)); counter.Increment(); }); Assert.IsFalse(counter.Completion.Wait(TimeSpan.FromMilliseconds(300))); }