Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!



C#
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
                      //});



                  }
Posted

1 solution

You already have the necessary code underneath the BeginInvoke line, but commented out:
C#
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)));
                }
            }
    }
}

According to this StackOverflow answer[^], the old APIs still exist for Silverlight apps, but not for Store apps.
 
Share this answer
 
Comments
[no name] 6-Nov-15 0:12am    
yup itremoved the error but now am getting this error

Additional information: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified
error please help

in objXmppclient = new XMPPClient();

i am in windows phone 8.1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900