public static OneShotDispatcherTimer CreateAndStart(TimeSpan duration, EventHandler callback) { var timer = new OneShotDispatcherTimer {Duration = duration}; timer.Fired += callback; timer.Start(); return timer; }
private void RequestCachePruning() { lock (this) { if (_cachePruningTimer != null || _cachePruningTimestamp.Add(CachePruningInterval) >= DateTime.UtcNow) { return; } Deployment.Current.Dispatcher.BeginInvoke(() => { if (_cachePruningTimer != null) { return; } _cachePruningTimer = OneShotDispatcherTimer.CreateAndStart(CachePruningTimerDuration, OnCachePruningTimerFired); }); } }
private void OnCachePruningTimerFired(object sender, EventArgs e) { if (sender != _cachePruningTimer) { return; } _cachePruningTimer = null; _cachePruningTimestamp = DateTime.UtcNow; ThreadPool.QueueUserWorkItem(state => PruneCache()); }