/// <summary> /// Rise event method /// </summary> public void SimulateCountdown() { TimerEventArgs e = new TimerEventArgs(); while (_milliseconds >= 0) { Console.Clear(); Console.WriteLine($"{_milliseconds / 1000} sec"); Thread.Sleep(1000); _milliseconds -= 1000; } e.Time = DateTime.Now; e.Milliseconds = _milliseconds; e.Message = "Timer was stopped!!"; OnTimer(e); }
protected virtual void OnTimer(TimerEventArgs e) { Volatile.Read(ref CountdownEvent)?.Invoke(this, e); }
/// <summary> /// Invokes all subscribers of <see cref="TimerEvent"/> /// </summary> /// <param name="sender"> The object which initialized the event </param> /// <param name="e"> Event arguments </param> protected virtual void OnTimeСome(object sender, TimerEventArgs e) { TimerEvent?.Invoke(this, e); }
// This is the method the CountdownTimer will call // when the countdown timer stop private void Listen(object sender, TimerEventArgs e) { Console.WriteLine($"{e.Message} at {e.Time}"); }