Example #1
0
 public void SetATime()
 {
     Console.WriteLine("请输入响铃时间,如:2019-03-20 11:00:00");
     try
     {
         string setTime = Console.ReadLine();
         ringTime = Convert.ToDateTime(setTime);
         Console.WriteLine("闹钟已设置为: " + setTime);
         while (true)
         {
             nowTime = new System.DateTime();
             nowTime = System.DateTime.Now;
             if (DateTime.Compare(nowTime, ringTime) >= 0)
             {
                 ALARMEventArgs args = new ALARMEventArgs()
                 {
                     hour   = nowTime.Hour,
                     minute = nowTime.Minute,
                     second = nowTime.Second
                 };
                 OnClock(this, args);
                 break;
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #2
0
 static void Ring(object sender, ALARMEventArgs args)
 {
     Console.WriteLine($"时间到了!");
 }