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.
在拥有控件基础句柄的线程上执行指定的委托