public void SetClock() { //接收闹钟设定的时间 Console.WriteLine("Input the clock time: (year,month,day,hour,minute,second)"); Console.WriteLine("The Clock goes off when the minute comes"); string s = Console.ReadLine(); DateTime time1 = DateTime.Parse(s); //DateTime time1 = new DateTime(2018, 10, 5, 9, 33, 0); //时间到达闹钟时间,发生一个事件,即通知外界 //闹钟的设定通知时间精确到分钟 while (ClockGoOff != null) { if (time1.Minute == DateTime.Now.Minute) { ClockEventArgs args = new ClockEventArgs(); args.clocktime = DateTime.Now; ClockGoOff(this, args); break; } else if (time1.Minute < DateTime.Now.Minute) { break; } } }
public void DoAlarm() { if (Alarm != null) { ClockEventArgs clock = new ClockEventArgs(); Alarm(this, clock); } }
public void DoClock() { if (Clocking != null) { ClockEventArgs args = new ClockEventArgs(); Clocking(this, args);//发生一次事件,即通知外界 } }
public void DoClock(int nHour, int nMinute) { while (DateTime.Now.Hour != nHour || DateTime.Now.Minute != nMinute) { } ClockEventArgs args = new ClockEventArgs(); AlarmClock(this, args); }
public void DoClock(int nHour, int nMinute) { //判断设定时间是否与当前时间相同 while (DateTime.Now.Hour != nHour || DateTime.Now.Minute != nMinute) { } //时间相同,发生事件,通知外界 ClockEventArgs args = new ClockEventArgs(); AlarmClock(this, args); }
public event ClockEventHandler timing; //定义事件,相当于申明一个委托实例,初值为null public void DoClock(string mytime) //触发DoClock事件 { ClockEventArgs args = new ClockEventArgs(); args.ding = mytime; timing(this, args); if (mytime == DateTime.Now.ToShortTimeString().ToString()) { Console.WriteLine("闹钟响了,起床啦!"); } else { Console.WriteLine("时间还没到,再睡一会吧!"); } }
public void set(DateTime tempTime) { ClockEventArgs args = new ClockEventArgs(); args.dateTime = DateTime.Now; args.clockTime = tempTime; while (args.dateTime < args.clockTime) { System.Threading.Thread.Sleep(1000); if (args.clockTime != args.dateTime) { args.dateTime = DateTime.Now; ClockSet(this, args); } } Console.WriteLine("闹钟时间到!"); }
public static void alarm(object sender, ClockEventArgs e) { Console.WriteLine("Ring!!!!"); }
static void ShowTime(object sender, ClockEventArgs e) { Console.WriteLine("闹钟剩余倒计时!"); }
//事件处理方法 static void ShowTime(object sender, ClockEventArgs e) { Console.WriteLine("The time now is " + e.clocktime); Console.WriteLine("The clock goes off!"); }
static void ShowProgress(object sender, ClockEventArgs e) { Console.WriteLine("时间到了"); }
static void follow(object sender, ClockEventArgs args) { Console.WriteLine("现在时间是:" + DateTime.Now.ToShortTimeString().ToString()); }
static void Show(object sender, ClockEventArgs e) { Console.WriteLine(e.Time.ToString() + " " + e.Infomation); }
static void Ring(object sender, ClockEventArgs e) { Console.WriteLine("it's time to get up"); }