/// <summary> /// Watches if the limit is reached. This is the "worker" method of the thread. /// </summary> /// <param name="timerThreadArgs">The arguments of the timer thread.</param> private void WatchTime(object timerThreadArgs) { TimerThreadArgs args = (TimerThreadArgs)timerThreadArgs; do { Thread.Sleep(args.Limit); this.FireLimitReached(this, new LimitReachedEventArgs()); }while (!args.Stop && args.Loop); }
/// <summary> /// Initializes a new instance of the <see cref="Timer"/> class. /// </summary> /// <param name="limit">The limit of the timer.</param> /// <param name="loop">A value indicating if the timer is running in a loop.</param> public Timer(int limit, bool loop = true) { this.timerThreadArgs = new TimerThreadArgs(limit, loop); this.timerThread = new Thread(this.WatchTime); }