public void SynchronizationContext_Now() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var res = s.Now - DateTime.Now; Assert.IsTrue(res.Seconds < 1); }
public void SynchronizationContext_ScheduleAction() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var ran = false; s.Schedule(() => { ran = true; }); Assert.IsTrue(ms.Count == 1); Assert.IsTrue(ran); }
public void SynchronizationContext_AlwaysPost_Different() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms, true); var ran = false; s.Schedule(() => { ran = true; }); Assert.True(ms.Count == 1); Assert.True(ran); }
public void SynchronizationContext_ScheduleAction_DateTimeOffset() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var e = new ManualResetEvent(false); s.Schedule(DateTimeOffset.Now.AddMilliseconds(100), () => { e.Set(); }); e.WaitOne(); Assert.IsTrue(ms.Count == 1); }
public void SynchronizationContext_ArgumentChecking() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); ReactiveAssert.Throws<ArgumentNullException>(() => new SynchronizationContextScheduler(null)); ReactiveAssert.Throws<ArgumentNullException>(() => new SynchronizationContextScheduler(null, true)); ReactiveAssert.Throws<ArgumentNullException>(() => s.Schedule<int>(42, default(Func<IScheduler, int, IDisposable>))); ReactiveAssert.Throws<ArgumentNullException>(() => s.Schedule<int>(42, DateTimeOffset.Now, default(Func<IScheduler, int, IDisposable>))); ReactiveAssert.Throws<ArgumentNullException>(() => s.Schedule<int>(42, TimeSpan.Zero, default(Func<IScheduler, int, IDisposable>))); }
public void SynchronizationContext_ScheduleAction_DateTimeOffset() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var e = new ManualResetEvent(false); s.Schedule(DateTimeOffset.Now.AddMilliseconds(100), () => { e.Set(); }); e.WaitOne(); Assert.True(ms.Count >= 1); // Can be > 1 in case of timer queue retry operations. }
public void SynchronizationContext_ArgumentChecking() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); ReactiveAssert.Throws <ArgumentNullException>(() => new SynchronizationContextScheduler(null)); ReactiveAssert.Throws <ArgumentNullException>(() => new SynchronizationContextScheduler(null, true)); ReactiveAssert.Throws <ArgumentNullException>(() => s.Schedule <int>(42, default(Func <IScheduler, int, IDisposable>))); ReactiveAssert.Throws <ArgumentNullException>(() => s.Schedule <int>(42, DateTimeOffset.Now, default(Func <IScheduler, int, IDisposable>))); ReactiveAssert.Throws <ArgumentNullException>(() => s.Schedule <int>(42, TimeSpan.Zero, default(Func <IScheduler, int, IDisposable>))); }
public void SynchronizationContext_ScheduleAction() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var ran = false; s.Schedule(() => { ran = true; }); Assert.True(ms.Count == 1); Assert.True(ran); }
public void SynchronizationContext_ScheduleAction_TimeSpan() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var e = new ManualResetEvent(false); s.Schedule(TimeSpan.FromMilliseconds(1), () => { e.Set(); }); e.WaitOne(); Assert.IsTrue(ms.Count == 1); }
public void ContextDisposable() { var disp = false; var m = new MySync(); var c = new ContextDisposable(m, Disposable.Create(() => { disp = true; })); Assert.IsFalse(m._disposed); Assert.IsFalse(disp); c.Dispose(); Assert.IsTrue(m._disposed); Assert.IsTrue(disp); }
public void SynchronizationContext_ScheduleAction_TimeSpan() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var e = new ManualResetEvent(false); s.Schedule(TimeSpan.FromMilliseconds(1), () => { e.Set(); }); e.WaitOne(); Assert.True(ms.Count == 1); }
public void SynchronizationContext_ScheduleActionDue() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var evt = new ManualResetEvent(false); var sw = new Stopwatch(); sw.Start(); s.Schedule(() => { sw.Stop(); evt.Set(); }, TimeSpan.FromSeconds(0.2)); evt.WaitOne(); Assert.IsTrue(sw.ElapsedMilliseconds > 180, "due " + sw.ElapsedMilliseconds); Assert.IsTrue(ms.Count == 1); }
public void SynchronizationContext_StartedCompleted() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var started = 0; s.Schedule <int>(42, TimeSpan.Zero, (self, x) => { started = ms.Started; return(Disposable.Empty); }); Assert.True(started == 1); Assert.True(ms.Count == 1); Assert.True(ms.Completed == 1); }
static void Main(string[] args) { AutoResetEvent myEvent = new AutoResetEvent(false); MySync mySync = new MySync(myEvent); ThreadPool.QueueUserWorkItem(mySync.ThreadMain); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); myEvent.Set(); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); Console.WriteLine("Finishing"); }
public void SynchronizationContext_ScheduleActionDue() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var evt = new ManualResetEvent(false); var sw = new Stopwatch(); sw.Start(); s.Schedule(TimeSpan.FromSeconds(0.2), () => { sw.Stop(); evt.Set(); }); evt.WaitOne(); Assert.True(sw.ElapsedMilliseconds > 180, "due " + sw.ElapsedMilliseconds); Assert.True(ms.Count == 1); }
public void SynchronizationContext_ScheduleActionError() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var ex = new Exception(); try { s.Schedule(() => { throw ex; }); Assert.True(false); } catch (Exception e) { Assert.Same(e, ex); } Assert.True(ms.Count == 1); }
public void SynchronizationContext_ScheduleActionError() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var ex = new Exception(); try { s.Schedule(() => { throw ex; }); Assert.Fail(); } catch (Exception e) { Assert.AreSame(e, ex); } Assert.IsTrue(ms.Count == 1); }
public void SynchronizationContext_AlwaysPost_Same() { var count = 0; var ran = false; var t = new Thread(() => { var ms = new MySync(); SynchronizationContext.SetSynchronizationContext(ms); var s = new SynchronizationContextScheduler(ms, true); s.Schedule(() => { ran = true; }); count = ms.Count; }); t.Start(); t.Join(); Assert.True(count == 1 /* post */); Assert.True(ran); }
public void ContextDisposable() { var disp = false; var m = new MySync(); var c = new ContextDisposable(m, Disposable.Create(() => { disp = true; })); Assert.AreSame(m, c.Context); Assert.IsFalse(m._disposed); Assert.IsFalse(disp); c.Dispose(); Assert.IsTrue(c.IsDisposed); Assert.IsTrue(m._disposed); Assert.IsTrue(disp); }
public void SynchronizationContext_StartedCompleted() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms); var started = 0; s.Schedule<int>(42, TimeSpan.Zero, (self, x) => { started = ms.Started; return Disposable.Empty; }); Assert.IsTrue(started == 1); Assert.IsTrue(ms.Count == 1); Assert.IsTrue(ms.Completed == 1); }
public void SynchronizationContext_AlwaysPost_Different() { var ms = new MySync(); var s = new SynchronizationContextScheduler(ms, true); var ran = false; s.Schedule(() => { ran = true; }); Assert.IsTrue(ms.Count == 1); Assert.IsTrue(ran); }
public void SynchronizationContext_AlwaysPost_Same() { var count = 0; var ran = false; var t = new Thread(() => { var ms = new MySync(); SynchronizationContext.SetSynchronizationContext(ms); var s = new SynchronizationContextScheduler(ms, true); s.Schedule(() => { ran = true; }); count = ms.Count; }); t.Start(); t.Join(); Assert.IsTrue(count == 1 /* post */); Assert.IsTrue(ran); }