Ejemplo n.º 1
0
        private static void ShowTime(MyClock sender)
        {
            MyTime time = sender.CurrentTime;

            Console.WriteLine($"Tick Event: " +
                              $"{time.Hour}:{time.Minute}:{time.Second}");
        }
Ejemplo n.º 2
0
        private static void ClockInNewthread(MyClock clock)
        {
            Thread thread = new Thread(clock.Run);

            thread.Start();
            while (Console.ReadKey() == null)
            {
                Thread.Sleep(500);
            }
            thread.Abort();
        }
Ejemplo n.º 3
0
        public static void Alarming(MyClock sender)
        {
            MyTime time = sender.CurrentTime;

            Console.WriteLine($"Alarm Event: {time.Hour}:{time.Minute}:{time.Second}");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("dingling dingling dingling");
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Main function
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     try {
         MyClock  clock      = new MyClock();
         MyAlarm  alarm      = new MyAlarm();
         DateTime systemTime = DateTime.Now;
         clock.AddAlarmTime(systemTime.Hour, systemTime.Minute, systemTime.Second, 5);;
         clock.AlarmEvent += new MyClock.TimeDelegate(alarm.Alarming); //添加一个委托实例
         clock.run();
     } catch (Exception e) {
         Console.WriteLine(e.Message);
     }
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                MyClock clock = new MyClock(); //时钟

                clock.AlarmTime = new MyTime(DateTime.Now.Hour,
                                             DateTime.Now.Minute,
                                             DateTime.Now.Second + 5);
                clock.TickEvent  += ShowTime;
                clock.AlarmEvent += Alarming;
                clock.Run();
                //ClockInNewthread(clock);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }