windows Phone8.1:UI不显示下一页,因为异步等待

本文关键字:一页 因为 异步 等待 显示 Phone8 UI windows | 更新日期: 2023-09-27 17:51:09

我想导航到下一页,但问题是我使用async和等待方法。

所以在后台frame.navigate(typeof(nextpage))导航我到下一页,但UI线程不导航和相同的页面仍然在屏幕上,但我可以在控制台中看到,frame.navigate正在工作,因为我正在传递参数。

下面是我的代码:
public async void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args)
        {
            string[] abc = new string[2];;
               System.Threading.CancellationTokenSource cts;
            cts = new System.Threading.CancellationTokenSource();

    string[] abc;
                ToastPrompt toast = new ToastPrompt();
                toast.Title = "Loading";
                toast.Message = "Please Wait";
                toast.Show();
                using (HttpClient client = new HttpClient())
                {
                    var response = client.GetAsync(new Uri("http://localhost:8080/impulse/total.jsp"));

                   string result = await responsefb.Content.ReadAsStringAsync();
                              try
                    {
                        Windows.Data.Json.JsonObject root = Windows.Data.Json.JsonValue.Parse(result).GetObject();
                        if (root["result"].GetString() == "true")
                        {
                            abc[0] = root["result"].GetString();
                            abc[1] = root["comment"].GetString();

                            Frame.Navigate(typeof(BasicPage1), abc);
                            System.Diagnostics.Debug.WriteLine("In IF");
                        }
                        else if(root["result"].GetString() == "false")
                        {
                             System.Diagnostics.Debug.WriteLine(root["result"].GetString());
                              abc[0] = root["comment"].GetString();
                             System.Diagnostics.Debug.WriteLine(abc);
                             toast.Hide();
                            cts.Cancel();
                            Frame.Navigate(typeof(signin),"hello");
                                    }
                        else 
                        { 
                        }
                    }
                    catch (Exception ex1)
                    {
                        System.Diagnostics.Debug.WriteLine("string is empty", ex1);
                    }
                }

My next page data

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // base.OnNavigatedTo(e);
            var lastPage = Frame.BackStack.Last().SourcePageType;
            System.Diagnostics.Debug.WriteLine(lastPage);
            if (lastPage.ToString() == "App13.fb")
            {
                try
                {
                    var a = e.Parameter.ToString();
                    System.Diagnostics.Debug.WriteLine(a);

                }
                catch (Exception Ex)
                {
                    System.Diagnostics.Debug.WriteLine(Ex.ToString());
                }
            }
            else
            {
            }
        }

windows Phone8.1:UI不显示下一页,因为异步等待

在UI线程中运行页面导航代码

var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
     Frame.Navigate(typeof(BasicPage1), abc);
});