private void TimerCallback(object state) { Action action = null; lock (this.m_lockObj) { if (this.m_executionInfo != null) { if (DateTime.Now - this.m_executionInfo.Timestamp >= TimeSpan.FromMilliseconds((double)this.m_delay)) { action = this.m_executionInfo.Action; this.m_executionInfo = (DelayedExecutor.ExecutionInfo)null; this.ChangeTimer(false); } } } if (action == null) { return; } try { action(); } catch (Exception ex) { Logger.Instance.Error("Exeption during delayed execution", ex); } }
public void AddToDelayedExecution(Action action) { lock (this.m_lockObj) this.m_executionInfo = new DelayedExecutor.ExecutionInfo() { Action = action, Timestamp = DateTime.Now }; this.ChangeTimer(true); }