[英]Windows form stopwatch elapsed time
我的窗体应用程序的任务是在时间等于 10 秒时调用方法和 checkBox1_CheckedChanged 事件。 但是程序不能去 if 语句做某事。
定时器:
private void timerAU_Tick(object sender, EventArgs e)
{
stopwatch.Start();
time = stopwatch.Elapsed.ToString(@"hh\:mm\:ss\.f");
TimerAutoUpdateHelper();
if (time.Equals("00:00:10.1"))
{
stopwatch.Reset();
timerAU.Stop();
thread.Join();
thread.Abort();
MessageBox.Show("OK!");
checkBox1_CheckedChanged(sender, e);
}
}
复选框:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
timerAU.Start();
stopwatch.Start();
thread = new Thread(() => DataProcess.DataFromPLC(new Form1()));
thread.Start();
Log.WriteLogFile(EventCategory.AUTOUPDATECHECKED);
}
else
{
stopwatch.Stop();
MessageBox.Show(time);
checkBox1.Checked = false;
timerAU.Stop();
thread.Join();
thread.Abort();
Log.WriteLogFile(EventCategory.AUTOUPDATEUNCHECKED);
}
}
解决了我的问题。 我更改了 if 语句并运行成功! :)
if (stopwatch.Elapsed > TimeSpan.FromSeconds(10))
{
stopwatch.Reset();
timerAU.Stop();
thread.Join();
MessageBox.Show("OK!");
checkBox1_CheckedChanged(sender, e);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.