C# DownloadFileAsync 回调未被触发
由于某种原因,我指定的异步回调似乎没有被调用。我在由原始应用程序线程启动的线程中得到了以下内容:
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += DownloadCompleted;
webClient.DownloadProgressChanged += DownloadProgressChanged;
webClient.DownloadFileAsync(new Uri(downloadUrl), tempPath);
对于我得到的回调:
public void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine("progress");
}
public void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
Console.WriteLine("completed");
}
我使用断点来验证 downloadUrl 和 tempPath 字符串是否都有效(并且我可以在Windows 资源管理器)。关于为什么回调不会被触发的任何见解?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论