using System;using System.Data.SqlClient;namespace Consoleapplication1{ class PRogram { private static System.Timers.Timer timer = new System.Timers.Timer(); static void Main(string[] args) { Console.WriteLine("Main -> {0:HH:mm:ss}", DateTime.Now); timer.Enabled = true; timer.Interval = 5 * 1000; timer.Start(); timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerEvent); Console.Read(); } private static void TimerEvent(object sender, System.Timers.ElapsedEventArgs e) { Console.WriteLine("TimerEvent -> {0:HH:mm:ss}", DateTime.Now); } }}如果想最开始就触发, 只能自己先调用一次了。
新闻热点
疑难解答