Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET ServicePoint对象生命周期_C#_.net_Http_Servicepointmanager_Servicepoint - Fatal编程技术网

C# .NET ServicePoint对象生命周期

C# .NET ServicePoint对象生命周期,c#,.net,http,servicepointmanager,servicepoint,C#,.net,Http,Servicepointmanager,Servicepoint,我一直在设置web API启动时的ServicePoint.ConnectionLeaseTimeout属性,以便使用ServicePointManager.FindServicePoint定期刷新连接以实现负载平衡。但是,我发现在为ServicePoint使用HTTP连接后的某个时间,ServicePoint.ConnectionLeaseTimeout已从我的设置值更改为默认值-1。 我肯定没有将服务点设置为-1。我的代码中的任意位置的ConnectionLaseTimeout都设置为-1,

我一直在设置web API启动时的
ServicePoint.ConnectionLeaseTimeout
属性,以便使用
ServicePointManager.FindServicePoint
定期刷新连接以实现负载平衡。但是,我发现在为ServicePoint使用HTTP连接后的某个时间,
ServicePoint.ConnectionLeaseTimeout
已从我的设置值更改为默认值-1。 我肯定没有将
服务点设置为-1。我的代码中的任意位置的ConnectionLaseTimeout
都设置为-1,并且我配置的其他服务点(未用于任何连接)仍处于配置值。 因此,我必须假设我最初配置的ServicePoint已被处置并替换为新的ServicePoint对象,其中
ServicePoint.ConnectionLaseTimeout
属性具有默认值

我知道当超过
ServicePointManager.MaxServicePoints
时,可以删除ServicePoints,但在我的应用程序中
ServicePointManager.MaxServicePoints
设置为0(无限制)。 我还知道,ServicePointManager.MaxServicePointIdleTime超过
ServicePointManager.MaxServicePointIdleTime
后,可能会处理ServicePoint,但我将其设置为int.MaxValue(~25天),而且这段时间肯定没有过

关于如何管理ServicePoint的生命周期以及如何更好地管理ServicePoint的配置(特别是ConnectionLeaseTimeout),是否有其他信息不需要在应用程序启动时简单地查找ServicePoint并对其进行一次设置?

显示ServicePoint对象被包装在对象中并存储在一个数据库中。WeakReference类型提供对对象的引用,同时仍允许垃圾回收回收该对象。因此,可能是垃圾回收器已处理ServicePoint,ServicePointManager随后重新生成新的ServicePoint对象以替换它,而该对象将不会保留ServicePointManager不控制的以前的配置值。
似乎没有办法静态配置ConnectionLeaseTimeout,以便将其应用于新创建的ServicePoint对象。

显示,当连接空闲时间超过该值时,TimerThreads用于删除ServicePoint对象。默认值为100秒。每个ServicePoint将使用创建ServicePoint时设置的空闲时间(对TimerThread.Queue的引用传递到ServicePoint构造函数),因此更新ServicePointManager.MaxServicePointIdleTime不会调整任何现有ServicePoint对象的MaxIdleTime,因此,在使用任何HTTP连接之前,请确保对此进行配置。

我无法保证声明的准确性,但有趣的是,我的情况确实如此。通过对类中的服务点进行私有引用,我阻止了重新应用默认值。