1. 代码
System.Timers.Timer timer1 = new System.Timers.Timer(1000);
private void timer1_Init()
{
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1Callback);
timer1.AutoReset = true;
timer1.Enabled = false;
}
private void timer1_start(int ms)
{
timer1.Stop();
timer1.Interval = ms;
timer1.Start();
}
private void timer1_stop()
{
timer1.Stop();
}
private void timer1Callback(object sender, EventArgs e)
{
Invoke((EventHandler)(delegate
{
}
)
);
}
2. 初始化
public Form1()
{
InitializeComponent();
timer1_Init();
}
3.用户程序中开启定时器
timer1_start(1000);