Windows 8类库为不同的线程编组

时间:2013-03-05 06:30:37

标签: windows-8

如果我尝试更新我的UI,则从Windows 8类库中收到此错误: The application called an interface that was marshalled for a different thread.由于Dispatcher.RunAsync方法不可用,我无法解决问题。

1 个答案:

答案 0 :(得分:0)

不是从其他线程更新UI的好方法。

为什么Dispatcher.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**.