2017-07-16 43 views

回答

0

下面应该工作。

Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, 
() => 
{ 
    // update your UI here 
    Update(i) 
}); 
+0

既然提到了原来的问题在视图模型类中运行,您可以使用'this.Dispatcher'来代替。如果应用程序拥有多个视图,依靠“MainView”会导致中断。 –

+0

我会在哪里使用这段代码,当我想调用'Update()'时,在Task中? –

+0

@AmirHusseinNargesian你可以把它放在Update()函数中,并在Dispatch处理程序中添加你的逻辑。 – thunderbird

-1

您可以使用下面的代码来运行代码:

await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.High/* the rank */, 
() => 
{ 
    // run the code 
}); 

我有另一种方式来做到这一点

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal /*the rank*/,() => { // run the code }); 

https://stackoverflow.com/a/38175976/6116637

+1

[文档](https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Core.CoreDispatcherPriority)明确表示不使用“High”值。 –

+0

@ PeterTorr-MSFT Thx,但我想说你可以在此设置排名。 – lindexi

相关问题