一、问题描述
进行winform 开发我们在进行数据交换时避免不了使用多线程或异步方法,这样操作也将避免不了跨线程对控件进行操作(赋值、修改属性)。
下面通过一个测试说明一下问题
点击一个按钮异步对textbox进行赋值
运行测试结果
1 private void button1_Click(object sender, EventArgs e) 2 { 3 Action<string> action = new Action<string>((str) => 4 { 5 // 解决跨线程赋值 6 this.textBox1.Text = str; 7 }); 8 action.BeginInvoke("Test", null, null); 9 }