作者:
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();
}