17
Face Palm Of The Day: Out-of-Order Calls Yields Out Of Order Results
In Categories: Uncategorized | No comments
In Categories: Uncategorized | No comments
The face palm of the day goes to this bit of code right here:
System.Net.WebClient client = new WebClient();
client.DownloadFileAsync(FileToDownload, OutputFilePath);
client.Proxy = WebRequest.GetSystemWebProxy();
client.Proxy.Credentials = CredentialCache.DefaultCredentials;
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
Looks fine right? Why then would I get the ’407 Proxy Auth’ error every single time it’s called?
Well kids, it all boils down to the simple fact that functional calls get called in order….event the ones that have the word ‘Async’ in them. As you can see I made the call to download the file immediately after I create the web client. This meant that no matter the proxy configuration or credentials I supplied, it wasn’t going to work…..and I mean I REALLLYYY tried to give it a plethora of configurations. I dropped the Async call to the bottom and it worked like a charm.
Hope this saves a face palm or two.