我不明白为什么主线程不交出控制权来处理结果。
public partial class NewTravelPage : ContentPage
{
public NewTravelPage()
{
InitializeComponent();
}
protected async override void OnAppearing()
{
var locator = CrossGeolocator.Current;
var position = await locator.GetPositionAsync();
var vanues = await VenueLogic.getVenues(position.Latitude, position.Longitude);
venueListView.ItemsSource = vanues;
}
}
我调用方法 getVenues:
public class VenueLogic
{
public async static Task<List<Venue>> getVenues(double latitude, double longitude)
{
List<Venue> vanues = new List<Venue>();
var url = VenueRoot.GenerateUrl(latitude, longitude);
using (HttpClient client = new HttpClient())
{
var res = await client.GetAsync("https://stackoverflow.com");
// here the code gives control to the main thread and stucks
var response = await res.Content.ReadAsStringAsync();
var venueRoot = JsonConvert.DeserializeObject<VenueRoot>
(response);
vanues = venueRoot.response.venues as List<Venue>;
}
return vanues;
}
}
使用.NetStandard;请帮忙!我不明白僵局发生在哪里
手掌心
相关分类