.net core ServicePoint中的CurrentConnections返回零
我试图在ServicePoint对象中查看CurrentConnections属性,但它始终为我返回零,即使我使用任何公共URI;我正在使用.NETCore。有人能告诉我我是否遗漏了什么吗 以下是我的测试用例片段:.net core ServicePoint中的CurrentConnections返回零,.net-core,servicepointmanager,servicepoint,.net Core,Servicepointmanager,Servicepoint,我试图在ServicePoint对象中查看CurrentConnections属性,但它始终为我返回零,即使我使用任何公共URI;我正在使用.NETCore。有人能告诉我我是否遗漏了什么吗 以下是我的测试用例片段: IHttpClientFactory clientFactory = serviceProvider.GetService<IHttpClientFactory>(); HttpClient client = clientFactory.C
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);
}
));
}
IHttpClientFactory客户端工厂=serviceProvider.GetService();
HttpClient=clientFactory.CreateClient();
var taskList=新列表();
foreach(可枚举范围(0,1000)中的var项)
{
taskList.Add(Task.Run)(异步()=>
{
HttpRequestMessage HttpRequestMessage=新的HttpRequestMessage(HttpMethod.Get)https://www.bing.com/");
ServicePoint ServicePoint=ServicePointManager.FindServicePoint(httpRequestMessage.RequestUri);
如果(servicePoint.CurrentConnections>0)
{
Assert.Fail($“找到非零连接={servicePoint.CurrentConnections}”);
}
返回wait client.sendaync(httpRequestMessage);
}
));
}
就是这样。谢谢你,汉斯。我想报告用于遥测目的的客户端服务点连接数。报告说我应该能够获得打开的连接数。所以,我想知道我是否错过了任何一步。如果是这样的话,在dotnetcore中是否有任何解决方法可以实现这一点?