c# - 增加 ServicePointManager.DefaultConnectionLimit 的缺点

标签 c# .net multithreading web-services

我在多线程环境中调用网络服务。由于操作超时或请求错误,我的很多调用都失败了,但是如果我以线性方式进行调用,则没有一个调用失败,这意味着使用多线程调用 web 服务存在问题。经过大量分析,我发现存在并发连接限制导致了这些异常,因此我通过添加以下代码修复了它。

 ServicePointManager.DefaultConnectionLimit = 2 * _ThreadCount;

我不知道增加此限制可能带来的不利影响。默认情况下,连接限制为 2。如果有人知道任何缺点,请告诉我。

最佳答案

MSDN说:

Changing the DefaultConnectionLimit property has no effect on existing ServicePoint objects; it affects only ServicePoint objects that are initialized after the change. If the value of this property has not been set either directly or through configuration, the value defaults to the constant DefaultPersistentConnectionLimit.

Note

Any changes to the DefaultConnectionLimit property affect both HTTP 1.0 and HTTP 1.1 connections. It is not possible to separately alter the connection limit for HTTP 1.0 and HTTP 1.1 protocols. When used in the server environment (ASP.NET) DefaultConnectionLimit defaults to higher number of connections, which is 10.

关于c# - 增加 ServicePointManager.DefaultConnectionLimit 的缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34922699/

相关文章:

c# - 如何在 C# 中使用 XmlNodeList 获取 xml 元素值

java - 这个基于 Apache 的 API 客户端类线程安全吗?

javascript - 如何将 JSON 对象从 ajax 传递到 ASP.net 页面

c# - 在 MVC 中设置 CaSTLe Windsor

c# - 使用 HttpWebRequest POST 到外部服务器上的表单

c# - 在 C# 中将分数转换为 float

.net - 使用自签名证书的 RabbitMQ 相互身份验证

c# - WPF/银光 : How to convert hex value into Color?

python - 当除 main 之外的所有线程都完成时执行操作? (Python)

Java:奇怪的死锁