在多线程操作界面控件或者组件的时候,经常会遇到一些问题。

我们在多线程操作控件的时候,一般都使用如下代码来操作。

delegate void MsgDel(string str);
protected void MsgEvent(string str)
{
          if (txtContent.InvokeRequired)
            {
                txtContent.BeginInvoke(new MsgDel(MsgEvent), str);
                return;
            }
        txtContent.Text=str;
}

但是Debug运行时,我仍然会遇到像如下问题“Cross-thread operation not valid: accessed from a thread other than the thread it was created on.”,不知道为什么,期待高手能够给予指点。

为了暂时解决这个问题,我暂时采用在主窗体添加下面代码的方式临时解决。

Control.CheckForIllegalCrossThreadCalls = false;  

相关文章:

  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
相关资源
相似解决方案