C# 无法将类型隐式转换为system.net

C# 无法将类型隐式转换为system.net,c#,C#,当我试图从远程服务器下载文件时,我的程序出错,我使用的是System.Net Lib,转换成它时出现问题 我收到了错误信息 无法隐式转换类型 “System.ComponentModel.AsyncCompletedEventHandler”到 System.Net.DownloadProgressChangedEventHandler' 在代码块的最后一行 AsyncCompletedEventHandler(client_DownloadFileCompleted); 误差线^ 表格五 u

当我试图从远程服务器下载文件时,我的程序出错,我使用的是System.Net Lib,转换成它时出现问题

我收到了错误信息

无法隐式转换类型 “System.ComponentModel.AsyncCompletedEventHandler”到 System.Net.DownloadProgressChangedEventHandler'

在代码块的最后一行

AsyncCompletedEventHandler(client_DownloadFileCompleted);
误差线^ 表格五

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Buildcraft_Installer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnStartDownload_Click(object sender, EventArgs e)
        {
            prgDownload.Visible = true;
                WebClient client = new WebClient();
                client.DownloadProgressChanged += new
                DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                client.DownloadProgressChanged += new
                AsyncCompletedEventHandler(client_DownloadFileCompleted);

如果有人有办法解决这个问题或找到解决方法以获得相同的结果,我将不胜感激。谢谢:

您可能想在最后一行中编写client.DownloadFileCompleted

您当前有两个对DownloadProgressChanged的调用,一个使用匹配的委托类型DownloadProgressChangedEventHandler,一个使用错误的AsyncCompletedEventHandler。

您在订阅最后一行的事件时使用了错误的委托

如果您使用Visual Studio,请写入+=并按Tab键,这样将生成具有正确签名的方法

但是我看到你上面的几行已经订阅了同一个活动,所以我的印象是你没有使用一个正确的活动来实现你想要实现的目标


应该有DownloadFileCompleted事件。我想这就是你想要的。

谢谢你,我对编程比较陌生,我倾向于犯简单的错误,但寻找复杂的答案,我一定是瞎了,因为我发誓我读了一遍又一遍。