[英]Cannot Implicitly Convert Type to system.net
I am having an error in my program when trying to download files from a remote server, I am using the System.Net
Lib and it is having an issue converting to it. 尝试从远程服务器下载文件时,程序中出现错误,我使用的是
System.Net
Lib,转换为它时出现问题。
I am getting the error Message 我收到错误消息
Cannot implicitly convert type 'System.ComponentModel.AsyncCompletedEventHandler' to System.Net.DownloadProgressChangedEventHandler'
无法将类型'System.ComponentModel.AsyncCompletedEventHandler'隐式转换为System.Net.DownloadProgressChangedEventHandler'
on the last line in the code block 在代码块的最后一行
AsyncCompletedEventHandler(client_DownloadFileCompleted);
Form.cs V Form.cs V
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);
I would be very grateful if anyone had a way to resolve this or a workaround to get the same result, thanks :) 如果有人有办法解决这个问题或解决方法以获得相同的结果,我将非常感谢,谢谢:)
You probably meant to write client.DownloadFileCompleted
on your last line. 您可能打算在最后一行编写
client.DownloadFileCompleted
。
You currently have two calls to DownloadProgressChanged
, one with a matching delegate type ( DownloadProgressChangedEventHandler
), one with the wrong one ( AsyncCompletedEventHandler
). 当前,您有两个对
DownloadProgressChanged
调用,一个具有匹配的委托类型( DownloadProgressChangedEventHandler
),一个具有错误的委托类型( AsyncCompletedEventHandler
)。
You use incorrect delegate
in subscription to the event on last line. 您在最后一行的事件订阅中使用了不正确的
delegate
。
If you use Visual Studio, write +=
and press Tab
key, so the method with correct signature will be generated. 如果使用Visual Studio,请编写
+=
并按Tab
键,这样将生成具有正确签名的方法。
But I see that a couple of lines above you already subscribed to the same event, so my impression is that you don't use a correct event for that what you want to achieve. 但是我看到您上方的两行已经订阅了同一事件,因此我的印象是,对于要实现的目标,您没有使用正确的事件。
There should be DownloadFileCompleted
event. 应该有
DownloadFileCompleted
事件。 I presume that is what you want. 我相信这是你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.