Beispiel #1
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();
        }
Beispiel #2
0
 public ScheduledTaskChangedEventArgs(ScheduledTask source, ScheduledTaskChangedAction action, double?interval)
 {
     Source   = source;
     Action   = action;
     Interval = interval;
 }