解决办法:

创建代理
delegate void SetTextCallback(string text);

创建和启动线程
this.demoThread = 
               new Thread(new ThreadStart(this.ThreadProcUnsafe));
               this.demoThread.Start();

线程中要求改主窗体UI中的text属性
private void ThreadProcSafe()
        {
            this.SetText("This text was set safely.");
        }

调用窗体中的函数用invoke传递参数
private void SetText(string text)
        {
            if (this.textBox1.InvokeRequired)
            {   
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                this.textBox1.Text = text;
            }
        }

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
  • 2022-02-10
相关资源
相似解决方案