For some reason, the Async开发者_如何学运维 callbacks I've specified don't seem to get called. I've got the following in a Thread started by the original application thread:
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += DownloadCompleted;
webClient.DownloadProgressChanged += DownloadProgressChanged;
webClient.DownloadFileAsync(new Uri(downloadUrl), tempPath);
And for the callbacks I've got:
public void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine("progress");
}
public void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
Console.WriteLine("completed");
}
I've used breakpoints to verify that the downloadUrl and tempPath strings are both valid (and I can see the downloaded file in Windows Explorer). Any insight on why the callbacks wouldn't be trigger? Thanks!
精彩评论