`
fuerbosi
  • 浏览: 466370 次
文章分类
社区版块
存档分类
最新评论

对 Windows 窗体控件进行线程安全调用的方法

 
阅读更多

子线程调用winform界面的 UI控件 的安全调用。

  1. delegate void SetTextCallback(string text); 创建委托
  2. private void SetText(string text)
    {
    // InvokeRequired required compares the thread ID of the
    // calling thread to the thread ID of the creating thread.
    // If these threads are different, it returns true.
    if (this.textBox1.InvokeRequired)
    {
    SetTextCallback d = new SetTextCallback(SetText);
    this.Invoke(d, new object[] { text });
    }
    else
    {
    this.textBox1.Text = text;
    }
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics