Пример #1
0
 public void ScheduledTask_Test()
 {
    // create and start the task
    var task = new ScheduledTask("Task", ct => Thread.Sleep(500), 100);
    task.Changed += (s, e) => ReportAction(e);
    task.Start();
    // allow the task time to be scheduled and run
    Thread.Sleep(5000);
    // stop the task
    task.Stop();
    // wait for completion (only in unit tests)
    task.Wait();
 }
Пример #2
0
        public void ScheduledTask_Test()
        {
            // create and start the task
            var task = new ScheduledTask("Task", ct => Thread.Sleep(500), 100);

            task.Changed += (s, e) => ReportAction(e);
            task.Start();
            // allow the task time to be scheduled and run
            Thread.Sleep(5000);
            // stop the task
            task.Stop();
            // wait for completion (only in unit tests)
            task.Wait();
        }
Пример #3
0
        public void ScheduledTask_WithCancellation_Test()
        {
            // create and start the task
            var task = new ScheduledTask("Task", ct => Thread.Sleep(500), 100);

            task.Changed += (s, e) => ReportAction(e);
            task.Start();
            // schedule a cancellation in 1 to 5 seconds
            var cancelTask = Task.Factory.StartNew(() =>
            {
                var random = new Random();
                Thread.Sleep(random.Next(1000, 5000));
                task.Cancel();
            });

            // allow the task time to be scheduled and run
            Thread.Sleep(5000);
            // stop the task
            task.Stop();
            // wait for completion (only in unit tests)
            task.Wait();
            // wait for completion of cancellation task
            cancelTask.Wait();
        }
Пример #4
0
 public void ScheduledTask_WithCancellation_Test()
 {
    // create and start the task
    var task = new ScheduledTask("Task", ct => Thread.Sleep(500), 100);
    task.Changed += (s, e) => ReportAction(e);
    task.Start();
    // schedule a cancellation in 1 to 5 seconds
    var cancelTask = Task.Factory.StartNew(() =>
    {
       var random = new Random();
       Thread.Sleep(random.Next(1000, 5000));
       task.Cancel();
    });
    // allow the task time to be scheduled and run
    Thread.Sleep(5000);
    // stop the task
    task.Stop();
    // wait for completion (only in unit tests)
    task.Wait();
    // wait for completion of cancellation task
    cancelTask.Wait();
 }