Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 同步主页面中异步任务的列表_C#_Xaml_Xamarin_Xamarin.forms_Async Await - Fatal编程技术网

C# 同步主页面中异步任务的列表

C# 同步主页面中异步任务的列表,c#,xaml,xamarin,xamarin.forms,async-await,C#,Xaml,Xamarin,Xamarin.forms,Async Await,我真的在寻找解决方案,但找不到合适的指导。 我在RestService.cs中使用了异步方法 public async static Task<List<Convert>> CheckBTCUSDAsync() { HttpClient client = new HttpClient(); string restUrl = "https://bitbay.net/API/Public/BTCUSD

我真的在寻找解决方案,但找不到合适的指导。 我在RestService.cs中使用了异步方法

 public async static Task<List<Convert>> CheckBTCUSDAsync()
        {
            HttpClient client = new HttpClient();
            string restUrl = 
    "https://bitbay.net/API/Public/BTCUSD/trades.json";
            HttpResponseMessage responseGet = await 
    client.GetAsync(restUrl);
            if (responseGet.IsSuccessStatusCode)
            {
                var response = await responseGet.Content.ReadAsStringAsync();
                List<Convert> currencies = Convert.FromJson(response);
                //Debug.WriteLine(currencies[0].Date);
                return currencies;
            }
            else
            {
                //Debug.WriteLine("***************");
                //Debug.WriteLine("*****FALSE*****");
                //Debug.WriteLine("***************");
                return null;
            }
        }

它挂起UI线程。有人知道解决这个问题的最佳/最简单的方法是什么吗?

这就是我如何让它在我的应用程序上运行的

var convert = Task.Run(() => RestService.CheckBTCUSDAsync()).Result;

为什么不从一开始就说呢?var convert=wait RestService.CheckBTCUSDAsync()@Jason我将阅读OnAppearing(),谢谢。太好了,它对我也有用:)我在不同的异步方法中尝试过类似的构造,但不知道它在同步方法中会有用:)非常感谢
var convert = Task.Run(() => RestService.CheckBTCUSDAsync()).Result;