示例#1
0
 public void ClockOnAlarm(Clock clock, ClockEventArgs args)
 {
     if (clock.AlarmHour == args.Hour && clock.AlarmMin == args.Min && clock.AlarmSec == args.Sec)
     {
         Console.WriteLine("Alarm..." + args.Hour + ":" + args.Min + ":" + args.Sec);
     }
 }
示例#2
0
 public void TimeTest(string s)
 {
     if (time == DateTime.Now.ToLongTimeString())
     {
         ClockEventArgs args = new ClockEventArgs();
         args.flag = true;
         bell(this, args);
     }//发生一个事件,即通知外界
 }
示例#3
0
 //每到闹铃时间Ring一次
 private static void Ring(object sender, ClockEventArgs cArgs)
 {
     if (cArgs.SecNum <= 10 &&
         cArgs.MinNum == ((Clock)sender).alarmTime.MinNum &&
         cArgs.HourNum == ((Clock)sender).alarmTime.HourNum)
     {
         Console.WriteLine($"RING RING RING ...");
     }
 }
示例#4
0
 //设置闹钟的函数,在里面调用事件
 public void SetAlarm(DateTime time)
 {
     //TimeSpan aTime = TimeSpan.FromMinutes(1);
     //time = DateTime.Now + aTime;
     if (OnClock != null)
     {
         ClockEventArgs args = new ClockEventArgs();
         args.Time = time;
         OnClock(this, args);
     }
 }
示例#5
0
        public Clock(int h, int m)
        {
            // 设置闹铃时间
            alarmTime = new ClockEventArgs
            {
                HourNum = h,
                MinNum  = m
            };

            // 设置闹钟初始时间0:04:50
            clockArgs         = new ClockEventArgs();
            clockArgs.HourNum = 0;
            clockArgs.MinNum  = 4;
            clockArgs.SecNum  = 50;
        }
示例#6
0
        public void InitClock(int hour, int min, int sec)
        {
            Console.WriteLine("init clock with " + hour + ":" + min + ":" + sec);
            ClockEventArgs args = new ClockEventArgs()
            {
                Hour = hour, Min = min, Sec = sec
            };

            while (true)
            {
                OnTick(this, args);
                OnAlarm(this, args);
                Thread.Sleep(1000);
            }
        }
示例#7
0
        // 每秒Tick一次
        private static void Tick(object sender, ClockEventArgs cArgs)
        {
            cArgs.SecNum++;
            if (cArgs.SecNum == 60)
            {
                cArgs.SecNum = 0;
                cArgs.MinNum++;
                if (cArgs.MinNum == 60)
                {
                    cArgs.MinNum  = 0;
                    cArgs.HourNum = (cArgs.HourNum + 1) % 24;
                }
            }

            Console.WriteLine($"[{cArgs.HourNum}:{cArgs.MinNum}:{cArgs.SecNum}]: TICK");
        }
示例#8
0
 static void ShowClock(object sender, ClockEventArgs e)
 {
     while (e.Time > DateTime.Now)
     {
         Console.Clear();
         Console.WriteLine("剩余时间为");
         Console.WriteLine(e.Time - DateTime.Now);
         System.Threading.Thread.Sleep(500);
     }
     Console.WriteLine("Time out");
     while (true)
     {
         Console.Beep();
         System.Threading.Thread.Sleep(100);
     }
 }
示例#9
0
 //在用户按下闹钟开关后,闹钟才可以开始走
 public void ClockOnTick(Clock clock, ClockEventArgs args)
 {
     args.Sec++;
     if (args.Sec == 60)
     {
         args.Sec = 0;
         args.Min++;
     }
     if (args.Min == 60)
     {
         args.Min  = 0;
         args.Hour = 0;
     }
     if (args.Hour == 24)
     {
         args.Hour = 0;
     }
     Console.WriteLine("Tick..." + args.Hour + ":" + args.Min + ":" + args.Sec);
 }
示例#10
0
        protected virtual void OnNotification(object sender, ClockEventArgs arg)
        {
            EventHandler <ClockEventArgs> temp = Notification;

            temp?.Invoke(sender, arg);
        }
示例#11
0
 /// <summary> Invoke TimeOut event </summary>
 /// <param name="sender"> Sender </param>
 /// <param name="e"> Arguments </param>
 private void OnTimeOut(object sender, ClockEventArgs e)
 {
     TimeOut?.Invoke(sender, e);
 }
示例#12
0
 static void ShowProgress(object sender, ClockEventArgs c)
 {
     Console.WriteLine("时间到!!!!");
     System.Threading.Thread.Sleep(10000);
 }
示例#13
0
 /// <summary> Write message in console when time is out </summary>
 /// <param name="sender"> Sender </param>
 /// <param name="e"> Arguments </param>
 private void TimeOut(object sender, ClockEventArgs e)
 {
     Console.WriteLine(e.Message);
 }
示例#14
0
 public void Clo_OnAlarm(object sender, ClockEventArgs args)
 {
     Console.WriteLine($"嘀嘀嘀,时间{clock.args.Hour}时{clock.args.Minu}分{clock.args.Sec}秒已经到了");
 }
示例#15
0
 public void Clo_OnTick(object sender, ClockEventArgs args)
 {
     Console.WriteLine($"时间为:{clock.args.Hour}时{clock.args.Minu}分{clock.args.Sec}秒");
 }
示例#16
0
 public Clock()
 {
     args = new ClockEventArgs();
 }