public IDisposable Schedule(TimeSpan delay, Action <IScheduler> action) { var timeoutObj = new TimeoutObject(action, this.Now.Add(delay)); this._timeoutObjects.Add(timeoutObj); return(timeoutObj); }
/// <summary> /// Removes the action and stops the thread if necessary. /// </summary> /// <param name="timeoutObj">The timeout obj.</param> private void RemoveInternal(TimeoutObject timeoutObj) { lock (this._timeoutObjects) { this._timeoutObjects.Remove(timeoutObj); if (this._timeoutObjects.Count == 0) { this.StopTimerThread(); } Monitor.PulseAll(this._timeoutObjects); } }
/// <summary> /// Adds the action and starts the thread if necessary. /// </summary> /// <param name="timeoutObj">The timeout obj.</param> private IDisposable AddInternal(TimeoutObject timeoutObj) { lock (this._timeoutObjects) { this._timeoutObjects.Add(timeoutObj); if (this._timeoutObjects.Count == 1) { this.StartTimerThread(); } Monitor.PulseAll(this._timeoutObjects); } return(timeoutObj); }