コード例 #1
0
        public void SecondTimeScheduler_1Task_ExecutedAtWholeSecond()
        {
            var timeStorage = new TimeStorage();
            var scheduler   = new SecondTaskScheduler();
            var factory     = new TaskFactory(scheduler);

            var task = factory.StartNew(() => timeStorage.LogTime(DateTime.UtcNow));

            task.Wait();

            VerifyTimes(timeStorage.GetTimes(), 1);
        }
コード例 #2
0
        public void SecondTimeScheduler_3Tasks_ExecutedAtWholeSecond()
        {
            var timeStorage = new TimeStorage();
            var scheduler   = new SecondTaskScheduler();
            var factory     = new TaskFactory(scheduler);
            var random      = new Random();

            var task1 = factory.StartNew(() => timeStorage.LogTime(DateTime.UtcNow));

            Thread.Sleep(random.Next(2000));
            var task2 = factory.StartNew(() => timeStorage.LogTime(DateTime.UtcNow));

            Thread.Sleep(random.Next(2000));
            var task3 = factory.StartNew(() => timeStorage.LogTime(DateTime.UtcNow));

            Task.WaitAll(task1, task2, task3);

            VerifyTimes(timeStorage.GetTimes(), 3);
        }