我试图在 ServicePoint 对象中查看 CurrentConnections 属性,但即使我使用任何公共 URI,它总是为我返回零;我正在使用 .NET Core。如果我遗漏了什么,有人可以告诉我吗?
这是我的测试用例的片段:
IHttpClientFactory clientFactory = serviceProvider.GetService<IHttpClientFactory>();
HttpClient client = clientFactory.CreateClient();
var taskList = new List<Task<HttpResponseMessage>>();
foreach (var item in Enumerable.Range(0, 1000))
{
taskList.Add(Task.Run(async () =>
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://www.bing.com/");
ServicePoint servicePoint = ServicePointManager.FindServicePoint(httpRequestMessage.RequestUri);
if (servicePoint.CurrentConnections > 0)
{
Assert.Fail($"Found non zero connection = {servicePoint.CurrentConnections}");
}
return await client.SendAsync(httpRequestMessage);
}
));
}