17,740
社区成员
发帖
与我相关
我的任务
分享
//主UI线程 按钮敲击后启动另一个线程,另一个线程进行耗时工作
private void btn_Click(object sender, RoutedEventArgs e)
{
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(doo));
th.Start();
}
void doo()
{
//模拟耗时工作
System.Threading.Thread.Sleep(2000);
//线程2通过Dispatcher安全修改UI
this.Dispatcher.BeginInvoke((System.Threading.ThreadStart)(() => { btn.Content = "MOD by another Thread"; }));
}