Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref='Timer' /> class.
        /// </summary>
        /// <param name="startDelay">The amount of time to delay before <see cref="Elapsed"/> event is invoked. Specify <see cref="TimeSpan.Zero"/> to start the timer immediately.</param>
        /// <param name="interval">The time interval on which to raise events. Min value is represented by <see cref="MinInterval"/> (1 millisecond). Max value is represented by <see cref="MaxInterval"/>.</param>
        /// <param name="handler">The <see cref="Elapsed"/> event handler.</param>
        /// <param name="autoResetMode">The auto reset mode.</param>
        public Timer(TimeSpan startDelay, TimeSpan interval, EventHandler <CancellationToken> handler = null, TimerAutoResetMode autoResetMode = TimerAutoResetMode.Exact)
        {
            Ensure.IsGreaterThanOrEqualToZero(startDelay, nameof(startDelay));
            Ensure.IsBetween(interval, MinInterval, MaxInterval, nameof(interval));

            StartDelay    = startDelay;
            Interval      = interval;
            AutoResetMode = autoResetMode;

            _timer = new System.Threading.Timer(TimerCallback, null, Timeout.Infinite, Timeout.Infinite);

            if (handler != null)
            {
                Elapsed += handler;
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Timer' /> class and sets <see cref="Interval"/> and <see cref="StartDelay"/> properties to the <paramref name="interval"/> value.
 /// </summary>
 /// <param name="interval">The time interval on which to raise events. Min value is represented by <see cref="MinInterval"/> (1 millisecond). Max value is represented by <see cref="MaxInterval"/>.</param>
 /// <param name="handler">The <see cref="Elapsed"/> event handler.</param>
 /// <param name="autoResetMode">The auto reset mode.</param>
 public Timer(TimeSpan interval, EventHandler <CancellationToken> handler = null, TimerAutoResetMode autoResetMode = TimerAutoResetMode.Exact)
     : this(interval, interval, handler, autoResetMode)
 {
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Timer' /> class and sets <see cref="Interval"/> and <see cref="StartDelay"/> properties to the default values (100ms).
 /// </summary>
 /// <param name="handler">The <see cref="Elapsed"/> event handler.</param>
 /// <param name="autoResetMode">The auto reset mode.</param>
 public Timer(EventHandler <CancellationToken> handler = null, TimerAutoResetMode autoResetMode = TimerAutoResetMode.Exact)
     : this(TimeSpan.FromMilliseconds(DEFAULT_INTERVAL_IN_MILLISECONDS), handler, autoResetMode)
 {
 }