Good day. I'm working on file downloader class using DownloadFileAsync. In normal situations everything works fine. But when I'm downloading file and disable network connection, downloading progress is just stops for infinite time, without raising any errors or calling any callbacks. Any ideas how to handle this situation? Many thanks.
_client.Proxy = WebRequest.DefaultWebProxy;
_client.DownloadProgressChanged += (sender, argv) => { actionCallback(argv.ProgressPercentage); }
_client.DownloadFileCompleted += (sender, argv) => {
if (argv.Error != null) {
_exc = argv.Error;
}
set event
}
Task.Factory.StartNew(() => {
_client.DownloadFileAsync(request, targetFileName);
thread sync
if (_exc != null) {
logger.ErrorException(exc);
throw;
}
The problem appears under Vista and 2k8. On Win7 everything is ok.
Add an event handler to the WebClient.OpenReadCompleted event. The OpenReadCompletedEventArgs has a boolean property for Error if an error occurred.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With