• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

[solved] C# WebClient object and catching exceptions with asynchronous methods

TheDude05

Limp Gawd
Joined
Jan 27, 2005
Messages
393
I'm using the C# WebClient object and if I run the method 'DownloadFileAsync' and the remote file does not exist (AKA, I get an http 404 from the server) a WebException is not thrown. However, all of the synchronous calls do raise the exception.

The only way I can tell if the server return a 404 is by checking the length of the file I'm downloading to. If its length is zero then the remote file didn't exist. Is there a better way to catch when this condition happens? Checking the length of the downloaded file just seems hackish to me.
 
Finally figured it out.

The asynchronous methods don't throw the exception but pass them along with the EventArgs object to the DownloadComplete event. (Someone correct me if I'm still wrong on that)
 
Back
Top