问题
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.
回答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>);
来源:https://stackoverflow.com/questions/10990152/c-sharp-metro-app-ui-update