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:
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");
}
精彩评论