public void Cancel() { var executionCount = 0; Action action = () => executionCount++; var timer = new TimerAction(action, 1, 2); timer.ExecuteOnFiberThread(); Assert.AreEqual(1, executionCount); timer.Dispose(); timer.ExecuteOnFiberThread(); Assert.AreEqual(1, executionCount); }
public void CallbackFromTimerWithCancel() { var mocks = new MockRepository(); var action = mocks.CreateMock<Action>(); var timer = new TimerAction(action, 2, Timeout.Infinite); var registry = mocks.CreateMock<ISchedulerRegistry>(); registry.Remove(timer); registry.Enqueue(timer.ExecuteOnFiberThread); mocks.ReplayAll(); timer.ExecuteOnTimerThread(registry); }
public void CallbackFromIntervalTimerWithCancel() { var mocks = new MockRepository(); var action = mocks.CreateMock<Action>(); var timer = new TimerAction(action, 2, 3); var registry = mocks.CreateMock<ISchedulerRegistry>(); registry.Remove(timer); mocks.ReplayAll(); timer.Dispose(); timer.ExecuteOnTimerThread(registry); }
///<summary> /// Enqueues action on to context after timer elapses. ///</summary> public IDisposable Schedule(Action action, long firstInMs) { if (firstInMs <= 0) { var pending = new PendingAction(action); _executionContext.Enqueue(pending.Execute); return pending; } else { var pending = new TimerAction(action, firstInMs, Timeout.Infinite); AddPending(pending); return pending; } }
///<summary> /// Enqueues action on to context after timer elapses. ///</summary> public IDisposable Schedule(Action action, int firstInMs) { if (firstInMs <= 0) { var pending = new PendingAction(action); _executionContext.Enqueue(pending.Execute); return(pending); } else { var pending = new TimerAction(action, firstInMs, Timeout.Infinite); AddPending(pending); return(pending); } }
private void AddPending(TimerAction pending) { Action addAction = delegate { if (_running) { _pending.Add(pending); pending.Schedule(this); } }; _executionContext.Enqueue(addAction); }
///<summary> /// Enqueues actions on to context after schedule elapses. ///</summary> public IDisposable ScheduleOnInterval(Action action, long firstInMs, long regularInMs) { var pending = new TimerAction(action, firstInMs, regularInMs); AddPending(pending); return pending; }