public void OnTask(object sender, TimerEventArgs ev) { this.Counter++; Console.WriteLine($"Just another second passed! Total count:{this.Counter}"); Console.WriteLine("Time is {0:hh.mm.ss}", ev.Time); Console.WriteLine(); if (this.Counter == MaxCounter) { StopListen((Timer)sender); } }
public void Start() { if (this.Interval == 0 || this.Interval < 0) { throw new ArgumentException("Time interval cannot be negative or zero!"); } while (true) { if (Task != null) { Thread.Sleep(this.Interval); var args = new TimerEventArgs(); Task(this, args); } } }