| 发表于:2007-01-09 12:39:4411楼 得分:0 |
使用timer.stop和start方法: public static system.timers.timer timer = new system.timers.timer(); public static mutex mx = new mutex(); static void main(string[] args) { timer.elapsed += new elapsedeventhandler(timer_elapsed); timer.interval = 3000; timer.start(); console.readline(); } static void timer_elapsed(object sender, elapsedeventargs e) { timer.stop(); //mx.waitone(); debug.writeline(system.datetime.now.tostring() + ": " + system.datetime.now.millisecond); system.threading.thread.sleep(1000); //mx.releasemutex(); timer.start(); } 输出如下: 2007-1-9 12:37:35:515 2007-1-9 12:37:40:390 2007-1-9 12:37:44:406 2007-1-9 12:37:48:406 2007-1-9 12:37:52:421 2007-1-9 12:37:56:437 2007-1-9 12:38:00:437 2007-1-9 12:38:04:468 2007-1-9 12:38:08:468 2007-1-9 12:38:12:484 2007-1-9 12:38:16:500 2007-1-9 12:38:20:500 2007-1-9 12:38:24:500 2007-1-9 12:38:28:500 2007-1-9 12:38:32:500 2007-1-9 12:38:36:562 2007-1-9 12:38:40:750 | | |
|