Oli*_*ver 2 c# asp.net-mvc asp.net-web-api2
出于诊断目的,我正在记录ServicePointManager.DefaultConnectionLimit.但奇怪的是它似乎正在返回Int32.MaxValue(即2147483647).
ServicePoint对象允许的最大并发连接数.默认值为2.
对于上下文,我在4.6.1上运行的ASP.Net 4应用程序中获取此值
根据@ Wimmel的链接,在ASP.Net中似乎将其设置Int32.MaxValue为HTTP运行时的一部分.
我们可以通过查看课堂上的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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1622 次 |
| 最近记录: |