public TimedDurableCacheQueue(IDurableCacheRefreshHandler handler, TimeSpan cleanupInterval) { _handler = handler; _timers = new ConcurrentDictionary<Guid, Timer>(); _cleanup = new Timer { AutoReset = true, Interval = cleanupInterval.TotalMilliseconds }; _cleanup.Elapsed += (s, e) => { var count = 0; foreach (var item in _timers) { if (!item.Value.Enabled) { Timer timer = null; if (_timers.TryRemove(item.Key, out timer)) { timer.Close(); timer.Dispose(); count++; } else { Trace.TraceWarning("Unable to remove timer from dictionary for key {0}", item.Key); } } } var timerCountAfterCleanup = _timers.Count; }; _cleanup.Start(); }
public TimedDurableCacheQueue(IDurableCacheRefreshHandler handler, TimeSpan cleanupInterval) { _handler = handler; _timers = new ConcurrentDictionary <Guid, Timer>(); _cleanup = new Timer { AutoReset = true, Interval = cleanupInterval.TotalMilliseconds }; _cleanup.Elapsed += (s, e) => { var count = 0; foreach (var item in _timers) { if (!item.Value.Enabled) { Timer timer = null; if (_timers.TryRemove(item.Key, out timer)) { timer.Close(); timer.Dispose(); count++; } else { Trace.TraceWarning("Unable to remove timer from dictionary for key {0}", item.Key); } } } var timerCountAfterCleanup = _timers.Count; }; _cleanup.Start(); }