C#多线程Invoke示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public void DoWork()
{
//错误示例:
textbox1.text = "Hello";

//正确示例:
textbox1.Invoke((str) => textbox1.text = str, new Object[]{ "Hello" });
}

private void button1_Click(object sender, EventArgs e)
{
//...
Thread tr = new Thread(new ThreadStart(DoWork));
tr.Start();
//...
}