1. Control.CheckForIllegalCrossThreadCalls = false;
多个线程同时操作时,有可能会造成控件损坏。变成一个大大地X。
2. 使用异步委托
private void button1_Click(object sender, EventArgs e)
{
Thread thrRun = new Thread(new ThreadStart(Run));
thrRun.Start();
}
void Run()
{
ChangeLabel1Text("hello");
}
void ChangeLabel1Text(string str)
{
this.BeginInvoke(new System.Threading.ThreadStart(delegate()
{
//this.label1.Text = str;
this.label1.Text = this.textBox1.Text;
}));
}
多个线程同时操作时,有可能会造成控件损坏。变成一个大大地X。
2. 使用异步委托
private void button1_Click(object sender, EventArgs e)
{
Thread thrRun = new Thread(new ThreadStart(Run));
thrRun.Start();
}
void Run()
{
ChangeLabel1Text("hello");
}
void ChangeLabel1Text(string str)
{
this.BeginInvoke(new System.Threading.ThreadStart(delegate()
{
//this.label1.Text = str;
this.label1.Text = this.textBox1.Text;
}));
}