views:

11

answers:

1

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