static void ShowAlarm(object sender, ClockArgs now) //设置每过一分钟闹钟触发一次 { if (now.Second == 0) { Console.WriteLine($"Alarm! DingRing! DingRing! DingRing! DingRing! DingRing!"); } }
public void TikTok() { this.second++; //时间前进1s if (this.second >= 60) { this.second = this.second % 60; this.minute++; if (this.minute >= 60) { this.minute = this.minute % 60; this.hour++; if (this.hour >= 24) { this.hour = this.hour % 24; } } } ClockArgs args = new ClockArgs() { Hour = this.hour, Minute = this.minute, Second = this.second }; Tick(this, args); Alarm(this, args); }
//事件处理方法 static void ShowTick(object sender, ClockArgs now) { Console.WriteLine($"TikTok! Time is {now.Hour}:{now.Minute}:{now.Second}"); }