2016-06-30 4 views

Antwort

0

Die HttpClient hat eine Timeout Eigenschaft. Setzen Sie das auf Timeout, das Sie wollen, und behandeln Sie die TimeoutException, um bestimmte Dinge auf dem Timeout zu tun.

HttpClient client = new HttpClient(); 
client.Timeout = TimeSpan.FromSeconds(5); 
HttpResponseMessage response = null; 
try 
{ 
    response = await client.GetAsync(url); 
} 
catch (TimeoutException) 
{ 
    // handle the timeout, e.g. return false 
    return false; 
} 
catch (Exception ex) 
{ 
    // handle the other errors, e.g. throw it 
    throw (ex); 
} 
Verwandte Themen