/// <summary> /// Creates a new timer object and starts it straight away /// </summary> /// <param name="callback">The callback.</param> /// <param name="dueTime">The amount of time to delay before callback is invoked. Specify TimeSpan.Zero to start the timer immediately.</param> /// <param name="period">The time interval between invocations of callback.</param> /// <param name="preciseTimerCallbackMode">The precise timer callback mode.</param> /// <returns></returns> public static PreciseTimer StartNew(TimerCallback callback, TimeSpan dueTime, TimeSpan period, PreciseTimerCallbackMode preciseTimerCallbackMode) { PreciseTimer preciseTimer = new PreciseTimer(callback, period, preciseTimerCallbackMode); preciseTimer.Start(dueTime, period, false); return(preciseTimer); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (!this._Disposed) { lock (this) { this._Disposed = true; if ((this._Timer != null)) { this._Timer.Dispose(); this._Timer = null; } if (this._PreciseTimer != null) { this._PreciseTimer.Stop(); this._PreciseTimer = null; } } } }
/// <summary> /// Creates the timer and sets the callback if it is enabled /// </summary> public void InitializeTimer() { if (_Timer == null && Enabled) { if (ExecuteDaily) { _Timer = new Timer(new TimerCallback(TimerThread), null, GetDailyDueTime(), TimeSpan.FromMilliseconds(-1)); } else { if (UsePreciseTimer) { _PreciseTimer = PreciseTimer.StartNew(new TimerCallback(PreciseTimerCallback), Interval, this.PreciseTimerCallbackMode); } else { _Timer = new Timer(new TimerCallback(TimerThread), null, Interval, Interval); } } } }