Using await client.GetAsync(uri) blocks my UI thread.
Here's the code inside my button click event handler:
private async void Button_Clicked(object sender, EventArgs e)
{
var vm = new MainPageViewModel();
HttpClient client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
var uri = new Uri(string.Format("http://localhost:50715/api/values"));
var response = await client.GetAsync(uri); // This is where UI gets blocked
SongView.ItemsSource = new List<Song>();
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
vm.Songs = await Task.Factory.StartNew(() =>
{
return JsonConvert.DeserializeObject<List<Song>>(content);
});
}
SongView.ItemsSource = vm.Songs;
}
And even with just this code it still blocks the UI on the same line.
private async void Button_Clicked(object sender, EventArgs e)
{
HttpClient client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
var uri = new Uri(string.Format("http://localhost:50715/api/values"));
var response = await client.GetAsync(uri); // This is where UI gets blocked
}
Can you point out what I'm doing wrong?
MaxResponseContentBufferSizein your code, especially in the second sample? Can you be more specific about the behavior you're seeing?await client.GetAsync(uri)is blocking the UI