楼主:
eggeggss (Suddenly I See)
2016-07-21 00:52:22如果非得在DoWork中跨UI执行绪,又不想锁main thread
有没有比较好的建议,谢谢
private void Retrive()
{
//thread.sleep 当作是画面绘制的工作
System.Threading.Thread.Sleep(5000);
this.txt.Text = "Complete!";
}
private void Btn_Click(object sender, RoutedEventArgs e)
{
BackgroundWorker bgn = new BackgroundWorker();
bgn.DoWork += (s1, e1) => {
functiondelegate funtionwork = new functiondelegate(Retrive);
//LOCK UI
this.Dispatcher.BeginInvoke(funtionwork, DispatcherPriority.Appl
icationIdle);
};
bgn.RunWorkerCompleted += (s1, e1) => {
this.txt.Text = "OK!";
};
bgn.RunWorkerAsync();
}