开发者

C# DownloadFileAsync Callbacks Not Being Triggered

开发者 https://www.devze.com 2023-03-30 01:09 出处:网络
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:

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消