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?
views:
11answers:
1
Q:
System.Net.WebClient.CancelAsync throws ObjectDisposedException -- "Cannot access a closed file."
+1
A:
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.
anvilis
2010-07-03 00:13:07