【发布时间】:2023-01-18 23:55:30
【问题描述】:
我使用此代码从链接下载文件:
WebClient webClient = new WebClient();
webClient.Headers.Add("Accept: text/html, application/xhtml+xml, */*");
webClient.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
webClient.DownloadFileAsync(new Uri(downloadURL), "C:\\Users\\" + Environment.UserName + "\\Documents\\AudioStreamerUpdate_" + rnd1.ToString() + ".zip");
//track the downloading progress
webClient.DownloadProgressChanged += (sender, e) =>
{
progressBar1.Value = e.ProgressPercentage;
label1updateinf.Text = e.ProgressPercentage + "%";
Console.WriteLine(e.ProgressPercentage + "%");
};
由于文件大约 200 Mb,我想跟踪下载进度。
我也试过这段代码:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressUpdate);
private void webClient_DownloadProgressUpdate(object sender, DownloadProgressChangedEventArgs e)
{
}
但它给了我这个错误:
“DownloadProgressCallback”没有重载匹配委托“DownloadProgressChangedEventHandler”
【问题讨论】: