ServicePointManager.MaxServicePointIdleTime 属性

定义

获取或设置 ServicePoint 对象的最大空闲时间。

public:
 static property int MaxServicePointIdleTime { int get(); void set(int value); };
public static int MaxServicePointIdleTime { get; set; }
static member MaxServicePointIdleTime : int with get, set
Public Shared Property MaxServicePointIdleTime As Integer

属性值

ServicePoint 对象的最大空闲时间(以毫秒为单位)。 默认值是 100,000 毫秒(100 秒)。

例外

示例

下面的代码示例设置此属性。

// Set the maximum number of ServicePoint instances to 
// maintain. If a ServicePoint instance for that host already 
// exists when your application requests a connection to
// an Internet resource, the ServicePointManager object
// returns this existing ServicePoint instance. If none exists 
// for that host, it creates a new ServicePoint instance.
ServicePointManager::MaxServicePoints = 4;

// Set the maximum idle time of a ServicePoint instance to 10 seconds.
// After the idle time expires, the ServicePoint object is eligible for
// garbage collection and cannot be used by the ServicePointManager.
ServicePointManager::MaxServicePointIdleTime = 10000;
// Set the maximum number of ServicePoint instances to
// maintain. If a ServicePoint instance for that host already
// exists when your application requests a connection to
// an Internet resource, the ServicePointManager object
// returns this existing ServicePoint instance. If none exists
// for that host, it creates a new ServicePoint instance.
ServicePointManager.MaxServicePoints = 4;

// Set the maximum idle time of a ServicePoint instance to 10 seconds.
// After the idle time expires, the ServicePoint object is eligible for
// garbage collection and cannot be used by the ServicePointManager object.
ServicePointManager.MaxServicePointIdleTime = 10000;
' Set the maximum number of ServicePoint instances to maintain.
' Note that, if a ServicePoint instance for that host already 
' exists when your application requests a connection to
' an Internet resource, the ServicePointManager object
' returns this existing ServicePoint. If none exists 
' for that host, it creates a new ServicePoint instance.
ServicePointManager.MaxServicePoints = 4

' Set the maximum idle time of a ServicePoint instance to 10 seconds.
' After the idle time expires, the ServicePoint object is eligible for
' garbage collection and cannot be used by the ServicePointManager.
ServicePointManager.MaxServicePointIdleTime = 10000

注解

属性MaxServicePointIdleTime设置对象在创建ServicePoint对象时分配给 MaxIdleTime 属性的最大空闲时间ServicePointManager。 对此值的更改仅 ServicePoint 影响在更改值后初始化的对象。

对象 ServicePoint 在 中指定的 MaxIdleTime时间处于空闲状态后,它有资格进行垃圾回收。 ServicePoint当与对象关联的连接列表为空时,ServicePoint对象处于空闲状态。

适用于

另请参阅