This code illustrates the blog article Better timeout handling with HttpClient.
Key features:
- control the timeout per request, rather than globally for all requests
- throw a more sensible exception (
TimeoutException
) when a timeout occurs, instead of the usualOperationCanceledException
Thanks, I found this helpful.
I thought about the inherit approach but then I must know all the places HttpWebRequest is created but on the other hand, only enrolling requests where I want this timeout behavior could be handy at instantiation.
Use ConfigureAwait(false) is my only suggestion since it highly unlikely the thread this is processed on matters.