I blogged before about the fact that it is better to re-use your HttpClient object instead of disposing and creating a new one for every request. There is however one caveat with a global HttpClient, and that is that DNS changes are not honored because the connections are re-used.
A solution is to set a connection timeout before your connection is released and recreated by using the ServicePointManager:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sp = ServicePointManager.FindServicePoint(new Uri("http://thisisasample.com")); | |
sp.ConnectionLeaseTimeout = 60*1000; //In milliseconds |
This will release the connection after 60 seconds.