" Dispatcher.BeginInvoke"似乎不存在!在windowsphone 8.1中 [英] "Dispatcher.BeginInvoke" seems not to be existing! in windowsphone 8.1

查看:94
本文介绍了" Dispatcher.BeginInvoke"似乎不存在!在windowsphone 8.1中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows Phone 8.1通用应用程序中使用Dispatcher.BeginInvoke方法。



但是,Dispatcher.BeginInvoke似乎不是现有的!



使用System.Windows.Threading;也不存在!



我收到namesepace不存在的错误消息,我可能错过了一个引用程序集。



我该怎么办?



我记得我在使用VS 2013开发Windows Phone 8.0项目时曾经使用过这种方法。 />


现在我有VS 2013和Windows 8.1通用应用程序项目(但我正在开发项目的Windows Phone 8.1部分)。





有什么问题?



感谢任何提示!







I am trying to use the method "Dispatcher.BeginInvoke" in a Windows Phone 8.1 Universal App.

However, "Dispatcher.BeginInvoke" seems not to be existing!

"using System.Windows.Threading;" also does not exist!

I get the error message that the namesepace does not exist and I may be missing a reference assembly.

What shall I do?

I remember that I used this method in past when developing a Windows Phone 8.0 Project with VS 2013.

Now I have VS 2013 and a Windows 8.1 Universal App Project (but I am developing the Windows Phone 8.1 part of the project).


What is wrong?

Thanks for any hints!



public void XMPPClient_OnStateChanged(object sender, EventArgs e)
      {
          switch (xmppClient.XMPPState)
          {
              case XMPPState.Ready:

                  if (IsXmppSuccess)
                  {
                      this.Dispatcher.BeginInvoke(() =>
                      {
                          NavigationService.Navigate((new Uri("/Output.xaml?key=success", UriKind.Relative)));//error

                      });


                      //var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
                      //var ignored = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                      //{
                      //    // update on ui thread
                      //});



                  }

推荐答案

你已经在 BeginInvoke 行下面有了必要的代码,但注释掉了:

You already have the necessary code underneath the BeginInvoke line, but commented out:
public async void XMPPClient_OnStateChanged(object sender, EventArgs e)
{
    switch (xmppClient.XMPPState)
    {
        case XMPPState.Ready:
            if (IsXmppSuccess)
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    NavigationService.Navigate((new Uri("/Output.xaml?key=success", UriKind.Relative)));
                }
            }
    }
}



根据此StackOverflow答案 [ ^ ],旧的API仍然适用于Silverlight应用程序,但不适用于商店应用程序。


According to this StackOverflow answer[^], the old APIs still exist for Silverlight apps, but not for Store apps.


这篇关于" Dispatcher.BeginInvoke"似乎不存在!在windowsphone 8.1中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆