I'm using C# .Net to call a web service asynchronously and would like to add a timeout. I cannot figure out how to catch the timeout exception correctly.
I'd rather not use the generic Exception since it's very broad. Preference is to catch the timeout exception specifically and alert the user of the timeout.
When a timeout occurs, if I print out the exception type, I get System.Net.WebException.
Is there a better way to catch the timeout exception?
HttpResponseMessage response = new HttpResponseMessage();
HttpClient client = new HttpClient();
client.Timeout = new TimeSpan(1);
client.BaseAddress = new Uri(dimURL);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Response Code
try
{
response = client.GetAsync(dimURL).Result;
}
catch (<CATCH TIMEOUT>)
{
}
catch (Exception e)
{ }