ServicePointManager.DefaultConnectionLimit返回Int32.MaxValue。

3
为了诊断目的,我正在记录ServicePointManager.DefaultConnectionLimit。然而奇怪的是,它似乎返回Int32.MaxValue(即2147483647)。
这似乎与MSDN文档上的说法相矛盾:
最大并发连接数由ServicePoint对象允许。默认值为2。
为了背景,我在运行4.6.1的ASP.Net 4应用程序中获取此值。

2
这是一个评论,在asp.net 4.5中为Web项目增加到了Int32.MaxValueSystem.Net.ServicePointManager.DefaultConnectionLimit == 24 --> BUG? - wimh
1个回答

9

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

我们可以通过查看System.Web程序集中的HttpRuntime来了解这一点。

有一个名为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;
}

ServicePointManager.DefaultConnectionLimit = int.MaxValue; 对我有效。谢谢。 - VolkanCetinkaya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接