System.Net.WebClient.CancelAsync抛出的ObjectDisposedException - "无法访问已关闭的文件" [英] System.Net.WebClient.CancelAsync throws ObjectDisposedException -- "Cannot access a closed file."

查看:471
本文介绍了System.Net.WebClient.CancelAsync抛出的ObjectDisposedException - "无法访问已关闭的文件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图下载一个文件异步使用WebClient类。我加入的事件处理程序DownloadProgressChanged和DownloadFileCompleted。如果我叫client.CancelAsync在下载进度的事件​​处理程序,我得到一个的ObjectDisposedException,告诉我该文件被关闭。如何正确取消异步文件下载?

I am attempting to download a file asynchronously using the WebClient class. I have added event handlers for DownloadProgressChanged and DownloadFileCompleted. If I call client.CancelAsync in the download progress event handler, I get an ObjectDisposedException, telling me the file is closed. How do I properly cancel an asynchronous file download?

推荐答案

原来,则会引发ObjectDisposedException,捕获并WebClient的忽略,如果该文件的下载速度足够快,该文件已被之后的进步改变事件仍在处理中关闭。

It turns out that ObjectDisposedException is thrown, caught and ignored by the WebClient if the file downloads sufficiently fast that progress change events are still being processed after the file has been closed.

这篇关于System.Net.WebClient.CancelAsync抛出的ObjectDisposedException - "无法访问已关闭的文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆