2011-05-14 135 views
0

我不能停止该定时器:无法停止计时器

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; 
     } 
    } 

我有一个消息框无穷大的数字! 任何想法?

+0

您是否看到'完成的'对话框? – Kamyar 2011-05-14 16:12:32

+0

首先停止计时器,然后用弹出窗口刺激用户。 – 2011-05-14 16:13:32

回答

4

一个消息块的执行,直到用户关闭它,首先停止计时器再展消息,否则您将被Windows发送垃圾邮件:

AppTimer.Enabled = false; 
MessageBox.Show("Finished"); 
1

试试这个,

if (BarreProgression.Value < BarreProgression.Maximum) 
     { 
      ... 
      BarreProgression.Value = BarreProgression.Value + 1; 
     } 
     else if (BarreProgression.Value == BarreProgression.Maximum) 
     { 

      //AppTimer.Stop(); 
      AppTimer.Enabled = false; 
      MessageBox.Show("Finished"); 
     } 
2

尝试移动你的计时器停止,更高的一条线:

 else if (BarreProgression.Value == BarreProgression.Maximum) 
    { 

     // This should be above the message box. 
     AppTimer.Enabled = false; 
     MessageBox.Show("Finished"); 
    }