日期:2014-05-18  浏览次数:20821 次

一个关于MessageBox弹出的问题,为什么显示后FormUpdate仍可以激活,涉及到线程
//主窗体
  private   void   FormUpdate_Load(object   sender,   EventArgs   e)
  {
            Thread   thUpdate   =   new   Thread(new   ThreadStart(UpdateProgram));
              thUpdate.Start();
  }

//更新线程调用的函数
  private   void   UpdateProgram()
{
          this.BeginInvoke(new     EventHandler(UpdateFinish));
  }

  //更新完成后在主界面上弹出一个messagebox提示
  private   void   UpdateFinish(object   sender,   EventArgs   e)
    {
            if   (this.InvokeRequired)  
              {       //如果不是在主线程,调用委托返回到主线程
                      this.Invoke(new   EventHandler(UpdateFinish));
                      return;
              }
                       
                MessageBox.Show( "更新完毕! ");
      }


按理说我的
MessageBox.Show( "更新完毕! ");
是在thUpdate线程中通过一个托触发的,也就是说在主界面上弹出的MessageBox,那为什么MessageBox弹出后,主界面仍可激活,此时的MessageBox不是dialog模式嘛,还是我程序写错了,请高手指点,急!

------解决方案--------------------
MessageBox.Show( "更新完毕! ",null);
return "更新完毕@ "!试试
------解决方案--------------------
anyway, 这样

MessageBox.Show(this, "message ");
------解决方案--------------------
没有你说的现象
主窗体不能激活。
------解决方案--------------------
MessageBox.Show( "更新完毕! ");
和他不是一个线程的
自然就。。。。
------解决方案--------------------
return "更新完毕 ";