System.Net.WebClient.CancelAsync throws ObjectDisposedException — “Cannot access a closed file.”

我只是一个虾纸丫 提交于 2019-12-24 07:57:34

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3169749/system-net-webclient-cancelasync-throws-objectdisposedexception-cannot-acces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!