gpt4 book ai didi

c# - ServicePointManager.DefaultConnectionLimit 返回 Int32.MaxValue

转载 作者:行者123 更新时间:2023-11-30 20:20:26 26 4
gpt4 key购买 nike

出于诊断目的,我正在记录 ServicePointManager.DefaultConnectionLimit。然而奇怪的是,它似乎正在返回 Int32.MaxValue(即 2147483647)。

这似乎与 MSDN documentation 矛盾关于主题:

The maximum number of concurrent connections allowed by a ServicePoint object. The default value is 2.

对于上下文,我在 4.6.1 上运行的 ASP.Net 4 应用程序中获取此值

最佳答案

根据@Wimmel 的链接,它在 ASP.Net 中似乎设置为 Int32.MaxValue 作为 HTTP 运行时的一部分。

我们可以通过looking inside the System.Web assembly at the HttpRuntime class看到这个.

有一个名为 SetAutoConfigLimits 的方法可以将其设置为 Int32.MaxValue。以下是相关摘录:

private void SetAutoConfigLimits(ProcessModelSection pmConfig)
{
int workerThreads;
int completionPortThreads;
ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
if (pmConfig.DefaultMaxWorkerThreadsForAutoConfig != workerThreads || pmConfig.DefaultMaxIoThreadsForAutoConfig != completionPortThreads)
UnsafeNativeMethods.SetClrThreadPoolLimits(pmConfig.DefaultMaxWorkerThreadsForAutoConfig, pmConfig.DefaultMaxIoThreadsForAutoConfig, true);
ServicePointManager.DefaultConnectionLimit = int.MaxValue;
}

关于c# - ServicePointManager.DefaultConnectionLimit 返回 Int32.MaxValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36792608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com