drupal hit counter
Jerry Huang | Translation between WP and Win8 Metro series: async anonymous method in Win8

Jerry Huang apps and developing apps

Translation between WP and Win8 Metro series: async anonymous method in Win8

1. November 2012 13:48 by Jerry in C#, Win8 Development, Windows Phone Development

As I mentioned previously, I'm trying to develop a Win8 Metro version of IP CAM Coontroller, so I'm basically translating the WP coding into Win8. I'm going to post a series of blog post to record (and so benefit those googler with same problem) some of the interesting issue and topic.

WP coding:

Code
1
2
3
4
5
6
 Deployment.Current.Dispatcher.BeginInvoke(() =>{//do something here});

WIN8

Code
1
2
3
4
5
6
7
  Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,new Windows.UI.Core.DispatchedHandler(() =>{//do something here}));

This is not end of the story, by using the RunAsync like above, you will get a compiler warning from VS2012, and it's interesting that if you assign the returning result (of RunAsync) to a variable, the warning goes away. So the final version is like:

Code
1
2
3
4
5
6
7
  var dummy = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,new Windows.UI.Core.DispatchedHandler(() =>{//do something here}));