예제 #1
0
        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);
        }
예제 #2
0
        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)));
        }