Application.Current.Dispatcher.Invoke UWP模拟

时间:2019-02-26 13:33:24

标签: c# .net uwp

UWP中是否存在Application.Current.Dispatcher.Invoke(例如WPF)的类似物?Application.Current.Dispatcher.Invoke(() => { //some code here });

2 个答案:

答案 0 :(得分:3)

Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
    // Do your stuff here
});

这将在UI线程上运行您的代码,将CoreDispatcherPriority.Normal更改为您喜欢的样式。

答案 1 :(得分:-1)

扩展Lloyd的回答:

async void SomeVoid(object sender, ElapsedEventArgs e) {
   await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
        //Your code here
   });
}