public void Run() { while (true) { if (this.second < 59) { this.second++; } else { this.second = 0; this.minute++; if (this.minute == 60) { this.minute = 0; this.hour = (this.hour + 1) % 24; } } TimeArgs currentTime = new TimeArgs() { Hour = hour, Minute = minute, Second = second }; if (this.hour == this.alarmHour && this.minute == this.alarmMinute && this.second == this.alarmSecond) { OnAlarm(this, currentTime); } else { OnTick(this, currentTime); } System.Threading.Thread.Sleep(1000); } }
private void Clock_OnTick(object sender, TimeArgs args) { Console.WriteLine($"Current time:{args.Hour}:{args.Minute}:{args.Second}"); }
private void Clock_OnAlarm(object sender, TimeArgs args) { Console.WriteLine($"Clock is alarming! Time:{args.Hour}:{args.Minute}:{args.Second}"); }