public void ClockRun(uint hour, uint min, uint sec) { ClockTime clockTime = new ClockTime { Hour = hour, Min = min, Sec = sec }; while (true) { Thread.Sleep(1000); clockTime.Sec += 1; if (clockTime.Sec == 60) { clockTime.Min += 1; clockTime.Sec = 0; } if (clockTime.Min == 60) { clockTime.Hour += 1; clockTime.Min = 0; } if (clockTime.Hour == 24) { clockTime.Hour = 0; } Tick(this, clockTime); Alarm(this, clockTime); } }
private void ClockRunning_Alarm(object sender, ClockTime clockTime) { if ((clockTime.Hour == ClockRunning.set_hour) && (clockTime.Min == ClockRunning.set_min) && (clockTime.Sec == ClockRunning.set_sec)) { Console.WriteLine("已经到设定时间~~~"); } else { return; } }
private void ClockRunning_Tick(object sender, ClockTime clockTime) { Console.WriteLine("嘀嗒......嘀嗒......[当前时间是:{0}:{1}:{2}]", clockTime.Hour, clockTime.Min, clockTime.Sec); }