Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
        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);
                }
            }
        }