Feb 09, 2021 10:20 AM|AlexBrodilin|LINK
I'm not sure if topic is still required to be answered. But just for people who will be looking for similar topic.
var response = (HttpWebResponse)await Request.GetResponseAsync();
TimeOut parameter applicable only for GetResponse() (synchronous one), not the GetResponseAsync(). In case of GetResponseAsync() TimeOut parameter will be totally ignored and getting request can stuck forever. For async method, unfortunately, custom timeout
mechanics should be implemented. That's how I solved it in my case.
int RequestTimeout = 30000;
var responseTask = request.GetResponseAsync();
WebResponse response = null;
if (await Task.WhenAny(responseTask, Task.Delay(RequestTimeout)) == responseTask)
response = await responseTask;
if (response != null)
throw new WebException("Async WebResponse timeout", WebExceptionStatus.Timeout);
The key is in WhenAny() method. responseTask will be killled once Delay is finished. Maybe it doesn't look clean, but it works for me.