/// <summary> /// Starts a new timer with the given state and signalling configuration /// </summary> /// <param name="callback"> /// Callback to be executed when the timer fires /// </param> /// <param name="state"> /// State object to be passed to the callback when the timer fires /// </param> /// <param name="dueTime"> /// Time before calling the callback after timer is created; specify -1 to prevent the timer from firing; /// specify 0 to fire immediately. /// </param> /// <param name="period"> /// Time interval between subsequents calls to the callback; specify a TimeSpan of -1 milliseconds to prevent /// periodic signalling. /// </param> /// <returns> /// A timer /// </returns> public static ITimer Timer(TimerCallback callback, object state, uint dueTime, uint period) { if (_frozen) { lock (_lock) { if (_frozen) { var timer = new FrozenTimer(callback, state, dueTime, period); Register(timer); return(timer); } } } return(new ThawedTimer(callback, state, dueTime, period)); }
/// <summary> /// Starts a new timer with signalling disabled, using the created timer as the state /// </summary> /// <param name="callback"> /// Callback to be executed when the timer fires /// </param> /// <returns> /// A timer /// </returns> public static ITimer Timer(TimerCallback callback) { if (_frozen) { lock (_lock) { if (_frozen) { var timer = new FrozenTimer(callback); Register(timer); return(timer); } } } return(new ThawedTimer(callback)); }