Windows Phone8.1:因异步等待而未显示下一页的UI

时间:2015-05-30 13:04:03

标签: c# windows-phone-8 windows-phone-8.1 async-await

我想导航到下一页,但问题是我正在使用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);
                    }

                }

我的下一页数据

 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
            {

            }
        }

1 个答案:

答案 0 :(得分:1)

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

Member