Call Async Method in Page_Load

前端 未结 3 1966
长发绾君心
长发绾君心 2021-01-20 07:58
static async void SendTweetWithSinglePicture(string message, string image)
{
    var auth = new SingleUserAuthorizer
    {
        CredentialStore = new SingleUserIn         


        
3条回答
  •  别那么骄傲
    2021-01-20 08:44

    Try This :

     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");
    
        await Task.WhenAll(clientcontacts, clienttemperature, clientlocation);
    
        var contacts =     Newtonsoft.Json.JsonConvert.DeserializeObject>(await clientcontacts);
        var location = Newtonsoft.Json.JsonConvert.DeserializeObject(await clientlocation);
        var temperature = Newtonsoft.Json.JsonConvert.DeserializeObject(await clienttemperature);
    
        listcontacts.DataSource = contacts;
        listcontacts.DataBind();
        Temparature.Text = temperature;
        Location.Text = location;
    }
    

提交回复
热议问题