Question

When I call .Abort() method of the request right after calling GetResponseAsync(), the request still does not abort instantly. There is significant (2-3 sec) delay before the abort actually happens.

As it seems, HttpWebRequest is first resolving host name and setting up a connection. So if the host name is wrong, or DNS server is dead, or the host itself does not respond, .Abort() will take ages to close the connection and abort the request.

Is there a way to instantly abort the operation and close the connection without waiting for these operations (hostname lookup, host connection setup, etc.) to complete?

Was it helpful?

Solution

The DNS resolution happens synchronously and the abort won't be effective until it's complete (or failed). There isn't much you can do about it, except execute the request in a separate thread and just "forget" about it when you need to abort.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top