使用异步C#时,“任务Home.HomeButton_ClickAsync具有错误的返回类型”

时间:2019-06-24 03:45:54

标签: c#

代码:

    private async Task HomeMoreButton_ClickAsync(object sender, EventArgs e)
    {
        InfoLabel_YearOfRelease.Show();

        using (var httpClient = new HttpClient())
        {
            var Json = await httpClient.GetStringAsync("http://www.omdbapi.com/?apikey=......=" + InfoNameOfShow.Text
             + "&type=" + InfoTypeOfShow.Text.ToLower());
            var ShowsExtendedInfo = new JavaScriptSerializer().Deserialize<ShowsExtendedInfo>(Json);

            InfoLabel_YearOfRelease.Text = ShowsExtendedInfo.Year;
        }
    }

错误:

  

CS0407 '任务Home.HomeMoreButton_ClickAsync(object,EventArgs)'具有错误的返回类型

在线:

  

this.HomeMoreButton.Click + = new   System.EventHandler( this.HomeMoreButton_ClickAsync );


我四处走动,但从未遇到此错误,也找不到任何在线帮助我的东西。

1 个答案:

答案 0 :(得分:0)

事件处理程序必须为async void 参见Async/Await - Best Practices in Asynchronous Programming