When I try the following code:
var request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 3; // a small value
var response = request.GetRes
Timeout
does not apply to asynchronous HttpWebRequest
requests. To quote the docs:
The Timeout property has no effect on asynchronous requests
I recommend you use HttpClient
instead, which was designed with asynchronous requests in mind.
Follow a solution to solve the problem.
await Task.Run(() => {
var varHttpResponse = varWebRequest.GetResponse();
});