无法停止计时器
本文关键字:计时器 无法停止 | 更新日期: 2023-09-27 17:56:31
我无法停止这个计时器:
private void startTimer_Click(object sender, EventArgs e)
{
AppTimer.Enabled = true;
}
private void AppTimer_Tick(object sender, EventArgs e)
{
if (BarreProgression.Value < BarreProgression.Maximum)
{
...
BarreProgression.Value = BarreProgression.Value + 1;
}
else if (BarreProgression.Value == BarreProgression.Maximum)
{
MessageBox.Show("Finished");
//AppTimer.Stop();
AppTimer.Enabled = false;
}
}
我有无限数量的消息框!有什么想法吗?
MessageBox 会阻止执行,直到用户关闭它,因此首先停止计时器,然后显示消息,否则您将被 Windows 发送垃圾邮件:
AppTimer.Enabled = false;
MessageBox.Show("Finished");
尝试将计时器停止向上移动一行:
else if (BarreProgression.Value == BarreProgression.Maximum)
{
// This should be above the message box.
AppTimer.Enabled = false;
MessageBox.Show("Finished");
}
试试这个,
if (BarreProgression.Value < BarreProgression.Maximum)
{
...
BarreProgression.Value = BarreProgression.Value + 1;
}
else if (BarreProgression.Value == BarreProgression.Maximum)
{
//AppTimer.Stop();
AppTimer.Enabled = false;
MessageBox.Show("Finished");
}