System.Net.WebClient.CancelAsync throws an ObjectDisposedException - "Unable to access the closed file."

I am trying to upload a file asynchronously using the WebClient class. I have added event handlers for DownloadProgressChanged and DownloadFileCompleted. If I call client.CancelAsync in the load execution event handler, I get an ObjectDisposedException telling me that the file is closed. How to cancel the download of an asynchronous file?

+1
source share
1 answer

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

+2
source

All Articles