开发者

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");
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜