By executing the following code, we get 1
public class Program
{
public static int count = 0;
static async Task Main(string[] args)
{
var handler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation
};
var client = new HttpClient(handler);
var tasks = new List<Task> {
client.GetAsync("https://www.microsoft.com"),
};
await Task.WhenAll(tasks);
var tasks2 = new List<Task> {
client.GetAsync("https://www.microsoft.com"),
};
await Task.WhenAll(tasks2);
Console.WriteLine("Count: "+count);
Console.ReadLine();
}
static bool ServerCertificateCustomValidation(HttpRequestMessage requestMessage, X509Certificate2 certificate, X509Chain chain,
SslPolicyErrors sslErrors)
{
Interlocked.Increment(ref count);
return true;
}
}
And no matter how many times we run requests, using the pool, the certificate verification will be interrupted.
This is bad, because I want to get the current expiration date for each request, is it possible to do something without disposing the handler?