用BackGroundWork吧
BackgroundWorker _backTask = new BackgroundWorker(); _backTask.DoWork += _backTask_DoWork; _backTask.RunWorkerCompleted += _backTask_RunWorkerCompleted; _backTask.RunWorkerAsync(); ------------------------------ void _backTask_DoWork(object sender, DoWorkEventArgs e) { Thread.Sleep(5000); } void _backTask_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show(LayoutRoot.ActualWidth.ToString() + " " + LayoutRoot.ActualHeight.ToString()); }
多线程,用计时器或者等待一直到结束模式
敢问大侠如何等待一直到结束
@溪山行旅丶:百度之~~
AutoResetEvent to sync the thread
楼上用异步正解,因为UI线程和你后台执行程序是一个线程,所以他会等后台执行完UI才会更新