试验 WebClient.DownloadFileAsync:
public void DownloadFile(string fileUrl, string localFile)
{
using (WebClient client = new WebClient())
{
downloadingFile = true;
client.DownloadFileCompleted += client_DownloadFileCompleted;
client.DownloadFileAsync(new Uri(fileUrl), localFile);
while (downloadingFile) { };
}
}
private void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
downloadingFile = false;
}
问题是 DownloadFileCompleted 事件永远不会被触发,所以我从未设置 downloadFile = false => while 循环永远不会完成。
关于出了什么问题的任何想法?
谢谢!