1

My problem is just the same as this link.

I am working on the new WinRT for Metro Applications in C#(win8 release preview). The problem is: My app My program runs a thread in the background which receives messages from the server(In fact, I ported a XMPP client app). Some information should be updated in the UI.

I have tried that link. The second method seems would work for me, but I has found there is no Dispatcher.Invoke(...) in the VS2012RC intellisense which means there is no this extension method.

After searching carefully, I think maybe this link can help me. But I have no idea how to start with my application in this scenario (since I am a beginner in C#).

Can you give me some advice? I would appreciate if you show some code snippet that would help me so much. Thanks a lot.

Community
  • 1
  • 1
zjalex
  • 125
  • 1
  • 12

1 Answers1

1

Somewhere in your UI thread run :

CoreDispatcher dispatcher = Windows.UI.CoreWindow.GetForCurrentThread().Dispatcher;

Then from your background thread call the RunAsync function in the dispatcher variable you just created.

dispatcher.RunAsync(DispatcherPriority.Normal, <delegate to run on UI thread>);
Leon Lucardie
  • 9,541
  • 4
  • 50
  • 70
  • Thanks. I will try it later. See this [link](http://stackoverflow.com/questions/10579027/run-code-on-ui-thread-in-winrt). – zjalex Jun 13 '12 at 01:12
  • I think should use CoreDispatcherPriority instead of DispatcherPriority. – zjalex Jun 13 '12 at 02:21