예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 ///<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;
     }
 }
예제 #5
0
 ///<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);
     }
 }
예제 #6
0
 private void AddPending(TimerAction pending)
 {
     Action addAction = delegate
                              {
                                  if (_running)
                                  {
                                      _pending.Add(pending);
                                      pending.Schedule(this);
                                  }
                              };
     _executionContext.Enqueue(addAction);
 }
예제 #7
0
 ///<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;
 }