【发布时间】:2012-01-09 17:30:51
【问题描述】:
public void InitTimer()
{
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 200; // in milliseconds
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("test");
}
使用来自How can I raise an event every hour (or specific time interval each hour) in .NET?的代码
我对 C# 非常陌生,但我不确定出了什么问题。我试图在此示例中每 2 秒显示一个消息框。没有错误,消息框根本不显示。
【问题讨论】:
-
200 毫秒!= 2 秒。
-
您遇到的实际问题是什么?你得到一个错误,或者代码根本没有被调用?
-
2 秒是 2000 毫秒,而不是 200
-
你确定你打电话给
InitTimer()? -
如果 timer1_Tick 函数需要 1 分钟才能完成怎么办?