- using System;
- using System.Timers;
- class TestTimer
- {
- public static void Main ()
- {
- Timer timer = new Timer();
- timer.Elapsed + = new ElapsedEventHandler(DisplayTimeEvent);
- timer.Interval = 1000;
- timer.Start();
- timer.Enabled = true;
- while (Console.Read ()! = 'q')
- {
- //-------------
- }
- }
- public static void DisplayTimeEvent (object source, ElapsedEventArgs e)
- {
- Console.Write({0}, DateTime.Now);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0911201513965.html
来源: http://www.codesnippet.cn/detail/0911201513965.html