Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Clock clock = new Clock();

            Console.WriteLine("请设置钟初始时间:");
            Console.WriteLine("StartHour: ");
            int hours = int.Parse(Console.ReadLine());

            Console.WriteLine("StartMinute: ");
            int minutes = int.Parse(Console.ReadLine());

            Console.WriteLine("StartSecond: ");
            int seconds = int.Parse(Console.ReadLine());

            clock.SetTime(hours, minutes, seconds);



            Console.WriteLine("请设置闹钟时间:");
            Console.WriteLine("AlarmHour: ");
            hours = int.Parse(Console.ReadLine());
            Console.WriteLine("AlarmMinute: ");
            minutes = int.Parse(Console.ReadLine());
            Console.WriteLine("AlarmSecond: ");
            seconds = int.Parse(Console.ReadLine());
            clock.SetAlarm(hours, minutes, seconds);
            clock.Tick  += Tick;
            clock.Alarm += Alarm;

            clock.Start();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Clock clock = new Clock(0, 0, 0);

            clock.Start();
            Console.ReadKey();
        }
Exemplo n.º 3
0
        //private static ClockHandler Tick;

        static void Main(string[] args)
        {
            Clock clock = new Clock(0, 5); // 0:05响铃

            clock.Run += Tick;
            clock.Run += Ring;
            clock.Start();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Clock clock = new Clock();

            clock.Alarm      += (s, e) => Console.WriteLine($"{e.Time} 的闹钟 {e.Message}");
            clock.Tick       += (s, e) => Console.WriteLine($"闹钟滴答作响 {e.Time:hh:mm:ss}");
            clock.ClockStart += (s, e) => Console.WriteLine("闹钟启动");
            clock.ClockStop  += (s, e) => Console.WriteLine("闹钟关闭");

            clock.AddAlarm(DateTime.Now.AddSeconds(5), "5秒之后的闹钟");
            clock.AddAlarm(DateTime.Now.AddSeconds(10), "10秒之后的闹钟");
            clock.AddAlarm(DateTime.Now.AddSeconds(30), "30秒之后的闹钟");

            clock.Start();

            Thread.Sleep(15 * 1000);
            clock.Stop();
            Thread.Sleep(20 * 1000);
        }