private static HttpClient GetHttpClientForSettings(WebServiceSettings settings, int connectionTimeoutSeconds) { return(ClientCache.GetOrAdd(settings, (sets) => { // Might get called more than once if e.g. many process instances execute at once, // but that should not matter much, as only one client will get cached var handler = new HttpClientHandler(); handler.SetHandlerSettingsBasedOnSettings(sets); var httpClient = new HttpClient(handler); httpClient.DefaultRequestHeaders.ExpectContinue = false; httpClient.Timeout = TimeSpan.FromSeconds(Convert.ToDouble(connectionTimeoutSeconds)); return httpClient; })); }