mephisto123
mephisto123

Reputation: 1448

How to instantly abort HttpWebRequest.GetResponseAsync()

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?

Upvotes: 0

Views: 798

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292405

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.

Upvotes: 1

Related Questions