线程间操作无效:从不是创建控件“textBox1”的线程访问它

来源:互联网 发布:ct三维重建软件 编辑:程序博客网 时间:2024/06/14 08:18
private delegate void SetTextCallback(string text);
//在给textBox1.text赋值的地方调用以下方法即可
private void SetText(string text)
{
    // InvokeRequired需要比较调用线程ID和创建线程ID
    // 如果它们不相同则返回true
    if (this.textBox1.InvokeRequired)
    {
        SetTextCallback d = new SetTextCallback(SetText);
        this.Invoke(d, new object[] { text });
    }
    else
    {
        this.textBox1.Text = text;
    }
}
阅读全文
0 0
原创粉丝点击