public void Dispatcher_ScheduleAction() { var id = Thread.CurrentThread.ManagedThreadId; var disp = EnsureDispatcher(); var sch = new DispatcherScheduler(disp); var evt = new ManualResetEvent(false); sch.Schedule(() => { Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); evt.Set(); }); evt.WaitOne(); disp.InvokeShutdown(); }
public void Dispatcher_ScheduleActionError() { var ex = new Exception(); var id = Thread.CurrentThread.ManagedThreadId; var disp = EnsureDispatcher(); var evt = new ManualResetEvent(false); disp.UnhandledException += (o, e) => { Assert.AreSame(ex, e.Exception.InnerException); // CHECK evt.Set(); e.Handled = true; }; var sch = new DispatcherScheduler(disp); sch.Schedule(() => { throw ex; }); evt.WaitOne(); disp.InvokeShutdown(); }
public void Dispatcher_ScheduleActionDue() { var id = Thread.CurrentThread.ManagedThreadId; var disp = EnsureDispatcher(); var sch = new DispatcherScheduler(disp); var evt = new ManualResetEvent(false); var sw = new Stopwatch(); sw.Start(); sch.Schedule(() => { sw.Stop(); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); sw.Start(); sch.Schedule(() => { sw.Stop(); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); evt.Set(); }, TimeSpan.FromSeconds(0.2)); }, TimeSpan.FromSeconds(0.2)); evt.WaitOne(); Assert.IsTrue(sw.ElapsedMilliseconds > 380, "due " + sw.ElapsedMilliseconds); disp.InvokeShutdown(); }
public void Dispatcher_Now() { var disp = EnsureDispatcher(); var res = new DispatcherScheduler(disp).Now - DateTime.Now; Assert.IsTrue(res.Seconds < 1); }
public void Dispatcher_ScheduleActionDueNow() { var id = Thread.CurrentThread.ManagedThreadId; var disp = EnsureDispatcher(); var sch = new DispatcherScheduler(disp); var evt = new ManualResetEvent(false); var sw = new Stopwatch(); sw.Start(); sch.Schedule(() => { sw.Stop(); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); sw.Start(); sch.Schedule(() => { sw.Stop(); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); evt.Set(); }, TimeSpan.Zero); }, TimeSpan.Zero); evt.WaitOne(); disp.InvokeShutdown(); }