WinRT中的全局调度器是什么?

6

我有一些类似这样的WP7代码:



using System.Windows;
using System.Windows.Threading;

public static class GlobalDispatcher
{
    public static Dispatcher Current { get { return Deployment.Current.Dispatcher; } }
}

在WinRT中有什么等效物?没有全局可访问的Dispatcher(或CoreDispatcher)对象吗?

3个回答

8
您需要使用Window.Current.Dispatcher

1
谢谢Jeff!对于其他寻找此内容的人,请注意它是Window.Current.Dispatcher。 - Aen

6

我认为,以下回答可以更好地解决问题:

如果应用程序没有焦点,则Window.Current为空,因此在涉及用户时可能会带来麻烦;)

然而,CoreApplication.MainView.CoreWindow.Dispatcher不为空...

– Jeremy White Aug 4 '13 at 13:09


2

试一下这个:

        var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            try
            {
               //Your code here
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接