// 先定义一个委托
public delegate void SetTextCallback(string text);
// 单击按钮
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(fun1));
t.Start();
}
// 线程函数体
private void fun1()
{
setText("hello");
}
// 设置文本函数
private void setText(string text)
{
if (label1.InvokeRequired)
{
SetTextCallback s = new SetTextCallback(setText);
Invoke(s, new string[] { text });
}
else
{
label1.Text = text;
}
}