问题
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