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

public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread t = new Thread(SetTextBox);
            t.Start();
        }

        private void SetTextBox()
        {
            //textBox1.Text = @"smart";//exception : 线程间操作无效: 从不是创建控件“textBox1”的线程访问它。
            Invoke(new Action(delegate { textBox1.Text = @"SMART"; }));
        }

 

说明:Invoke(delegate)

Executes the specified delegate on the thread that owns the control's underlying window handle.

在拥有控件基础句柄的线程上执行指定的委托

posted on 2011-09-27 15:13  雨渐渐  阅读(229)  评论(0)    收藏  举报

导航