C# 项目中的错误

本文关键字:错误 项目 | 更新日期: 2023-09-27 18:33:57

这是我的两个函数:

 public void SetCompanies()
    //set the Companies table from Shret.net DataBase
    {
        try
        {
            WebClient webClient = new WebClient();
            Uri uri = new Uri("http://api.sherut.net/?method=Company");
            webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
            try
            {
                webClient.OpenReadAsync(uri);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    void webClient_OpenReadCompleted(object sender, OpenWriteCompletedEventArgs e)
    {
        try
        {
            DataContractJsonSerializer serializer = null;
            var companies = (Companies)serializer.ReadObject(e.Result);
            foreach (Company c in companies.data)
            {
                MessageBox.Show(c.Name + " " + c.CompanyID);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}

这是我得到的错误:

"'webClient_OpenReadCompleted'匹配委托没有重载 'System.Net.OpenReadCompleteEventHandler'"

我不明白为什么,因为我在这个函数之后编写了处理程序......提前感谢!

C# 项目中的错误

OpenReadCompleted不需要OpenWriteCompletedEventArgs