Ejemplo n.º 1
0
        public event TimeEventHandler Alarm;//将时间Alarm与委托关联
        public void DoTime()
        {
            Console.WriteLine("请输入闹钟时间:");
            Console.WriteLine("请输入小时:");
            int timeH = int.Parse(Console.ReadLine());

            Console.WriteLine("请输入分钟:");
            int timeM = int.Parse(Console.ReadLine());

            Console.WriteLine("请输入秒:");
            int timeS = int.Parse(Console.ReadLine());

label1:
            DateTime time = DateTime.Now;

            if (time.Hour == timeH && time.Minute == timeM && time.Second == timeS)
            {
                if (Alarm != null)    //代理触发事件
                {
                    TimeEventArgs args = new TimeEventArgs();
                    args.NowTime = DateTime.Now;
                    Alarm(this, args);
                }
            }
            else
            {
                goto label1;
            }
        }
Ejemplo n.º 2
0
        public event TimeEventHandler Alarm;//将时间Alarm与委托关联
        public void DoTime()
        {
            DateTime time = DateTime.Now;

            Console.WriteLine("请输入闹钟时间:");
            DateTime time1 = Console.ReadLine();

            if (time == time1)
            {
                if (Alarm != null)//代理触发事件
                {
                    TimeEventArgs args = new TimeEventArgs();
                    args.NowTime = DateTime.Now.Hour;
                    Alarm(this, args);
                }
            }
        }
Ejemplo n.º 3
0
 static void ShowTime(object sender, TimeEventArgs timeEventArgs)
 {
     Console.WriteLine("时间到了!");
 }