WindowsRT里Dispatcher更新Ui线程的变化

以前WPF或Silverlight里用Dispatcher更新UI线程是这样:

 

Dispatcher.BeginInvoke(() =>

{

     MessageBox.Show("成功");

});

 

现在WindowsRT里要这样:

 

 this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(async () =>
{
       MessageDialog msg = new MessageDialog("成功");
       await msg.ShowAsync();
})).AsTask();

 

或者:

 

this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(OnDispatched)).AsTask();

public async void OnDispatched()
 {
       MessageDialog msg = new MessageDialog("成功");
       await msg.ShowAsync();
}

 

 

posted @ 2012-07-08 01:30  therockthe  阅读(284)  评论(0)    收藏  举报