ASP.Net Async ASPX page / ASCX control

Date: 2017-04-11

Source: https://www.hanselman.com/blog/TheMagicOfUsingAsynchronousMethodsInASPNET45PlusAnImportantGotcha.aspx

 
<%@ Page Title="Async" Language="C#" CodeBehind="Async.aspx.cs" Inherits="Whatever" Async="true" %> 
public void Page_Load(object sender, EventArgs e)
{
    RegisterAsyncTask(new PageAsyncTask(LoadSomeData));
}
public async Task LoadSomeData()
 {

 var clientcontacts = Client.DownloadStringTaskAsync("api/contacts");

 var clienttemperature = Client.DownloadStringTaskAsync("api/temperature");

 var clientlocation = Client.DownloadStringTaskAsync("api/location");

var contacts = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Contact>>(await clientcontacts);
 var location = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(await clientlocation);
 var temperature = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(await clienttemperature);

listcontacts.DataSource = contacts;
 listcontacts.DataBind();
 Temparature.Text = temperature;
 Location.Text = location;
 }
7130cookie-checkASP.Net Async ASPX page / ASCX control