/// <summary> /// Simulates timer countdown. On zero invokes OnEndTime method to notify subscribers. /// </summary> /// <param name="waitSeconds">Amount of seconds to wait.</param> public void SimulateEndTime(int waitSeconds) { var startTime = DateTime.Now; while (waitSeconds != 0) { if (DateTime.Now.Second - startTime.Second == 1) { startTime = DateTime.Now; waitSeconds--; } } EndTimeEventArgs args = new EndTimeEventArgs(); OnEndTime(args); }
/// <summary> /// Notifies all subscribers about event. /// </summary> /// <param name="eventArgs">Contains information about event</param> protected virtual void OnEndTime(EndTimeEventArgs eventArgs) { EndTime?.Invoke(this, eventArgs); }
private void FirstListenerMsg(object sender, EndTimeEventArgs args) { Console.WriteLine("First listener message:"); Console.WriteLine($"Time ended on = {args.timeOfEvent.TimeOfDay}"); }