C#自动化执行程——定时器Timer

System.Windows.Forms.Timer是应用于WinForm中的,

缺点是计时不精确,而且必须有消息循环,Console Application(控制台应用程序)无法使用。

使用System.Timers.Timer类

Timer time = new Timer();
time.Interval = 1500; //执行Tick的周期
time.Enabled = true; //定时时间处于运行状态
time.Tick += new EventHandler(time_Tick);

public void time_Tick(object source, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("OK!");
}
原文地址:https://www.cnblogs.com/StarZhai/p/10028971.html