2013-03-05 24 views
0

從Windows 8類庫如果我試圖更新我的用戶界面,我得到此錯誤: The application called an interface that was marshalled for a different thread.由於Dispatcher.RunAsync方法不可用,我無法解決問題。Windows 8類庫編組爲不同的線程

回答

0

不是從其他線程更新UI的好方法。

爲什麼Dispacher.RunAsync不可用?

this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => 
{ 
    YourMethod(); 
}); 

或嘗試爲等待任務使用:

this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => 
{ 
    YourMethod()(); 
}).AsTask().Wait(); 

**this** is reference to **Window.Current**. 
+0

非常感謝它解決了我的問題。在我的類庫代碼中,「this」被引用到Window.Current中。當我解析「Dispatcher」的引用時,它將引用「System.ServiceModel.Dispatcher」而不是「Window.Current.Dispatcher」 – Manic 2013-03-05 10:02:45

相關問題