c# 计时器 System.Timers.Timer

第一次计时正确,从第二次计时开始明显快了很多,比如第一次计时2.25秒,第二次4.32秒,
第三次7.03秒,越来越快,这是怎么回事。代码如下:
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "开始检查")
{
Thread t1 = new Thread(new ThreadStart(time1start));
t1.Start();
//time1.Start();
Thread t2 = new Thread(new ThreadStart(checkstart));
t2.Start();
}
else if (button1.Text == "重新检查")
{
t = 0;
//如何正在计时,则先停止再清零,否则直接清零
if (this.timer1.Enabled == true)
{
this.timer1.Enabled = false;
textBox1.Text = GetAllTime(t);
}
else
{
textBox1.Text = GetAllTime(t);
}
Thread t1 = new Thread(new ThreadStart(time1start));
t1.Start();
//time1.Start();
Thread t2 = new Thread(new ThreadStart(checkstart));
t2.Start();
button1.Text = "重新检查";
}
}
private void time1start()
{
//设置timer可用
timer1.Enabled = true;
//设置timer
timer1.Interval = 10;
//设置是否重复计时,如果该属性设为False,则只执行timer_Elapsed方法一次。
timer1.AutoReset = true;
timer1.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
private void checkstart()
{
conventionlabel3Click(null, null);
conventionlabel4Click(null, null);
conventionlabel5Click(null, null);
timer1.Enabled = false;
if (button1.Text == "开始检查")
{
button1.Text = "重新检查";
}

}

查看全部
xu_life
life清者自清
2016/12/12 07:02
  • c#
  • 计时器
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复