【发布时间】:2010-12-02 20:43:20
【问题描述】:
我有一个格式为http://ww.url.com/page?id=200 的网址。这将下载一个 10 MB 的文件。但是,我总是将 e.ProgressPercentage 设为 0。但它正在使用实际结果读取的上传完成功能。
请告诉我我在这里做错了什么。
我正在使用以下代码
private void button1_Click(object
sender, EventArgs e)
{
WebClient webClient = new WebClientEx();
webClient.DownloadProgressChanged +=
new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
webClient.DownloadDataCompleted += new
DownloadDataCompletedEventHandler(wc_DownloadComplete);
webClient.DownloadDataAsync(new Uri("http://ww.url.com/page?id=200"));
}
public void wc_DownloadProgressChanged(Object sender,
DownloadProgressChangedEventArgs e)
{
Progress1.Value = e.ProgressPercentage; // this is 0
}
public void wc_DownloadComplete(Object sender,DownloadDataCompletedEventArgs e)
{
int a = 0;
this.Close();
}
} }
【问题讨论】:
-
可能是你的格式(-:)引起的
-
请注意:您的 CompletedEvent 缺少错误处理。
标签: c# winforms .net-3.5 download webclient