/// <summary> /// Runs the specified ticker delegate periodically. /// </summary> /// <param name="tickerDelegate">The ticker delegate.</param> /// <param name="timeSpan">The time span.</param> /// <returns>An interruptible handle for external control of the ticker.</returns> public static IInterruptible Periodically( FirePeriodicallyTicker tickerDelegate, TimeSpan timeSpan) => new FirePeriodicallyContext( tickerDelegate, null, timeSpan);
/// <summary> /// Runs the specified ticker delegate periodically. /// </summary> /// <param name="tickerDelegate">The ticker delegate.</param> /// <param name="milliseconds">The milliseconds.</param> /// <returns>An interruptible handle for external control of the ticker.</returns> public static IInterruptible Periodically( FirePeriodicallyTicker tickerDelegate, int milliseconds) => new FirePeriodicallyContext( tickerDelegate, null, milliseconds);
/// <summary> /// Runs the specified ticker delegate periodically. /// </summary> /// <param name="tickerDelegate">The ticker delegate.</param> /// <param name="payload">The payload.</param> /// <param name="timeSpan">The time span.</param> /// <returns>An interruptible handle for external control of the ticker.</returns> public static IInterruptible Periodically( FirePeriodicallyTicker tickerDelegate, object payload, TimeSpan timeSpan) => new FirePeriodicallyContext( tickerDelegate, payload, timeSpan);
/// <summary> /// Runs the specified ticker delegate periodically. /// </summary> /// <param name="tickerDelegate">The ticker delegate.</param> /// <param name="payload">The payload.</param> /// <param name="milliseconds">The milliseconds.</param> /// <returns>An interruptible handle for external control of the ticker.</returns> public static IInterruptible Periodically( FirePeriodicallyTicker tickerDelegate, object payload, int milliseconds) => new FirePeriodicallyContext( tickerDelegate, payload, milliseconds);
internal FirePeriodicallyContext( FirePeriodicallyTicker tickerDelegate, object?state, int milliseconds) : this( tickerDelegate, state, TimeSpan.FromMilliseconds(milliseconds)) { }
internal FirePeriodicallyContext( FirePeriodicallyTicker tickerDelegate, object?state, TimeSpan timeSpan) : this( tickerDelegate, state, TimeSpan.Zero, timeSpan) { }
internal FirePeriodicallyContext( FirePeriodicallyTicker tickerDelegate, object?state, TimeSpan initialDelay, TimeSpan timeSpan) { this.state = state; this.timeSpan = timeSpan; timer = new Timer( TimerTick !, Requires.NotNull(tickerDelegate), initialDelay, timeSpan); }