public void CancelOperations_Success() { Scheduler <CancellableScheduledAction> scheduler = new Scheduler <CancellableScheduledAction>(TimeSpan.FromSeconds(0.1)); CancellableScheduledAction action1 = new CancellableScheduledAction(); scheduler.Tasks.Add(new ScheduledTask <CancellableScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(100.0), Weekdays.All), action1, true, null, null)); CancellableScheduledAction action2 = new CancellableScheduledAction(); scheduler.Tasks.Add(new ScheduledTask <CancellableScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(200.0), Weekdays.All), action2, true, null, null)); scheduler.Start(); ManualResetEvent.WaitAny(new WaitHandle[] { action1.Waiter, action2.Waiter }); Stopwatch watch = Stopwatch.StartNew(); scheduler.Stop(); Assert.IsTrue(watch.ElapsedMilliseconds < 200); scheduler.Dispose(); }
public void CancelOperations_Success() { Scheduler<CancellableScheduledAction> scheduler = new Scheduler<CancellableScheduledAction>(TimeSpan.FromSeconds(0.1)); CancellableScheduledAction action1 = new CancellableScheduledAction(); scheduler.Tasks.Add(new ScheduledTask<CancellableScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(100.0), Weekdays.All), action1, true, null, null)); CancellableScheduledAction action2 = new CancellableScheduledAction(); scheduler.Tasks.Add(new ScheduledTask<CancellableScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(200.0), Weekdays.All), action2, true, null, null)); scheduler.Start(); ManualResetEvent.WaitAny(new WaitHandle[] { action1.Waiter, action2.Waiter }); Stopwatch watch = Stopwatch.StartNew(); scheduler.Stop(); Assert.IsTrue(watch.ElapsedMilliseconds < 200); scheduler.Dispose(); }