protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Thread checkMsgBoxThread = new Thread(RefreshMsgBoxTopmost);
            checkMsgBoxThread.Start();
        }
private void RefreshMsgBoxTopmost()
        {
            if (this.InvokeRequired == false)
            {
                SetMsgBoxTopmost();
            }
            else
            {
                SetMsgBoxTopmostDelegate setMsgBoxTopmostDelegate = new SetMsgBoxTopmostDelegate(SetMsgBoxTopmost);
                this.BeginInvoke(setMsgBoxTopmostDelegate, null);
            }
        }
private void SetMsgBoxTopmost()
        {
            while (true)
            {
                foreach (Form frm in XconMessageBox.FormList)
                {
                    frm.TopMost = true;
                }
                Thread.Sleep(2000);
            }
        }
代码没什么特别的。

解决方案 »

  1.   

    while (true)
                {
                    foreach (Form frm in XconMessageBox.FormList)
                    {
                        frm.TopMost = true;
                    }
                    Thread.Sleep(2000);
                }
    这还不特别吗?
    你既然知道定义委托,线程里怎么不调用委托呢,为什么要直接操作窗体?
      

  2.   

    而且,你把线程的代码和委托的代码写反了
    有while的部分应该定义成线程,而赋值的部分定义成委托
    你在委托函数里调用while,不卡死了
      

  3.   


    void SetMsgBoxTopmost()
    {
    if (this.InvokeRequired)
    {
    SetMsgBoxTopmostDelegate setMsgBoxTopmostDelegate = new SetMsgBoxTopmostDelegate(SetMsgBoxTopmost);
                    this.BeginInvoke(setMsgBoxTopmostDelegate, null);
    }
    else
    {
                    foreach (Form frm in XconMessageBox.FormList)
                    {
                        frm.TopMost = true;
                    }
    }
    }这里是递归调用
    先在线程里调用,判断它是需要Invork的,则执行Invork通知主线程来调用自身
    然后主线程调用,判断不需要Invork,直接执行foreach赋值