public void RemoveEvent(TimerEvent evt) { lock (_timerEvents) { _timerEvents.Remove(evt); evt.Stop(); } }
public void AddEvent(TimerEvent evt) { lock (_timerEvents) { _timerEvents.Add(evt); if (Started) { evt.Start(); } } }
public void Event_Auto_Starts_When_Running() { long count = 0; TimerRuntimeService timerService = new TimerRuntimeService(); var evt = new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100)); DeliveryCore deliveryCore = new DirectDeliveryCore(); using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService)) { runtime.Start(); Thread.Sleep(500); long curCount = Interlocked.Read(ref count); Assert.AreEqual(0, curCount); timerService.AddEvent(evt); Thread.Sleep(500); curCount = Interlocked.Read(ref count); runtime.Stop(); Assert.GreaterOrEqual(curCount, 3); } }
void onTimerElapsed(object sender, ElapsedEventArgs e) { if (!_timer.AutoReset) { _timer.Interval = Interval.TotalMilliseconds; _timer.AutoReset = true; _timer.Start(); } Action action = Action; if (action != null) { _current = this; try { action(); } finally { _current = null; } } }
public void RegisterHeartbeat(Heartbeat heartbeat) { lock (_heartbeats) { var timerService = getTimerService(); _heartbeats.Add(heartbeat); TimerEvent evt = new TimerEvent(heartbeatTick, heartbeat.Interval, heartbeat); timerService.AddEvent(evt); _events.Add(heartbeat, evt); } }