[英]Can't stop a timer
I can't stop this timer : 我不能停止这个计时器:
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;
}
}
I have an infinity number of message boxes! 我有无数个消息框! Any ideas?
有任何想法吗?
A MessageBox blocks the execution until the user closes it so first stop the timer then show the message or you will get spammed by windows: MessageBox会阻止执行,直到用户关闭它为止,因此请先停止计时器,然后显示消息,否则Windows会向您发送垃圾邮件:
AppTimer.Enabled = false;
MessageBox.Show("Finished");
Try to move your Timer stop, one line higher: 尝试将您的计时器档位移高一行:
else if (BarreProgression.Value == BarreProgression.Maximum)
{
// This should be above the message box.
AppTimer.Enabled = false;
MessageBox.Show("Finished");
}
try this, 尝试这个,
if (BarreProgression.Value < BarreProgression.Maximum)
{
...
BarreProgression.Value = BarreProgression.Value + 1;
}
else if (BarreProgression.Value == BarreProgression.Maximum)
{
//AppTimer.Stop();
AppTimer.Enabled = false;
MessageBox.Show("Finished");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.