예제 #1
0
        public void CallParallelAsyncTest()
        {
            bool?t1Called = false; int d1 = 1000;
            bool?t2Called = false; int d2 = 2000;
            bool?t3Called = false; int d3 = 1000;

            Stopwatch sw     = Stopwatch.StartNew();
            var       result = ActionTools.CallParallelAsync(
                () => { Task.Delay(d1).Wait(); t1Called = true; },
                () => { Task.Delay(d2).Wait(); t2Called = true; },
                () => { Task.Delay(d3).Wait(); t3Called = true; }
                );

            Assert.IsTrue(sw.ElapsedMilliseconds < TestTimingTolerance);

            Thread.Sleep(Math.Max(d3, Math.Max(d1, d2)) + TestTimingTolerance);

            Assert.IsTrue(result.IsCompleted);
            Assert.IsTrue(t1Called.Value);
            Assert.IsTrue(t2Called.Value);
            Assert.IsTrue(t3Called.Value);
            Assert.IsTrue(Math.Abs(result.Result - sw.ElapsedMilliseconds) < 2 * TestTimingTolerance);
        }