c# 跨线程调用控件的方法
//WinForm用法
Thread thread = new Thread(p=> { Action action = new Action(() => { System.Windows.Forms.MessageBox.Show("test"); }); action.Invoke(); }); thread.IsBackground = true; thread.Start();
//WPF用法
Thread thread = new Thread(p=> {
this.Dispatcher.Invoke(new Action(delegate {System.Windows.Forms.MessageBox.Show("test");}));
}); thread.IsBackground = true; thread.Start();
- 上一篇 »java多线程调用静态方法安全吗?
- 下一篇 »C# 跨线程赋值的简单做法