コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
 public void DoAlarm()
 {
     if (Alarm != null)
     {
         ClockEventArgs clock = new ClockEventArgs();
         Alarm(this, clock);
     }
 }
コード例 #3
0
 public void DoClock()
 {
     if (Clocking != null)
     {
         ClockEventArgs args = new ClockEventArgs();
         Clocking(this, args);//发生一次事件,即通知外界
     }
 }
コード例 #4
0
        public void DoClock(int nHour, int nMinute)
        {
            while (DateTime.Now.Hour != nHour || DateTime.Now.Minute != nMinute)
            {
            }
            ClockEventArgs args = new ClockEventArgs();

            AlarmClock(this, args);
        }
コード例 #5
0
        public void DoClock(int nHour, int nMinute)
        {
            //判断设定时间是否与当前时间相同
            while (DateTime.Now.Hour != nHour || DateTime.Now.Minute != nMinute)
            {
            }
            //时间相同,发生事件,通知外界
            ClockEventArgs args = new ClockEventArgs();

            AlarmClock(this, args);
        }
コード例 #6
0
        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("时间还没到,再睡一会吧!");
            }
        }
コード例 #7
0
        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("闹钟时间到!");
        }
コード例 #8
0
 public static void alarm(object sender, ClockEventArgs e)
 {
     Console.WriteLine("Ring!!!!");
 }
コード例 #9
0
 static void ShowTime(object sender, ClockEventArgs e)
 {
     Console.WriteLine("闹钟剩余倒计时!");
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: Amber0306/CSharpHomework
 //事件处理方法
 static void ShowTime(object sender, ClockEventArgs e)
 {
     Console.WriteLine("The time now is " + e.clocktime);
     Console.WriteLine("The clock goes off!");
 }
コード例 #11
0
 static void ShowProgress(object sender, ClockEventArgs e)
 {
     Console.WriteLine("时间到了");
 }
コード例 #12
0
 static void follow(object sender, ClockEventArgs args)
 {
     Console.WriteLine("现在时间是:" + DateTime.Now.ToShortTimeString().ToString());
 }
コード例 #13
0
 static void Show(object sender, ClockEventArgs e)
 {
     Console.WriteLine(e.Time.ToString() + "  " + e.Infomation);
 }
コード例 #14
0
 static void Ring(object sender, ClockEventArgs e)
 {
     Console.WriteLine("it's time to get up");
 }