ServicePoint.MaxIdleTime 属性

定义

获取或设置与 ServicePoint 对象关联的连接在关闭前可以持续空闲的时间。

public:
 property int MaxIdleTime { int get(); void set(int value); };
public int MaxIdleTime { get; set; }
member this.MaxIdleTime : int with get, set
Public Property MaxIdleTime As Integer

属性值

ServicePoint 对象关联的连接在关闭和重用于另一个连接前可以持续空闲的时间长度(以毫秒为单位)。

例外

示例

下面的代码示例使用 MaxIdleTime 属性来设置和检索 ServicePoint 空闲时间。

// Display the date and time that the ServicePoint was last 
// connected to a host.
Console::WriteLine( "IdleSince = {0}", sp->IdleSince );

// Display the maximum length of time that the ServicePoint instance  
// is allowed to maintain an idle connection to an Internet  
// resource before it is recycled for use in another connection.
Console::WriteLine( "MaxIdleTime = {0}", sp->MaxIdleTime );
// Display the date and time that the ServicePoint was last
// connected to a host.
Console.WriteLine("IdleSince = " + sp.IdleSince.ToString());

// Display the maximum length of time that the ServicePoint instance
// is allowed to maintain an idle connection to an Internet
// resource before it is recycled for use in another connection.
Console.WriteLine("MaxIdleTime = " + sp.MaxIdleTime);
' Display the date and time that the ServicePoint was last 
' connected to a host.
Console.WriteLine(("IdleSince = " + sp.IdleSince.ToString()))


' Display the maximum length of time that the ServicePoint instance 
' is allowed to maintain an idle connection to an Internet  
' resource before it is recycled for use in another connection.
Console.WriteLine(("MaxIdleTime = " + sp.MaxIdleTime.ToString()))

注解

可以将 设置为 MaxIdleTimeTimeout.Infinite 以指示与 ServicePoint 对象关联的连接永远不会超时。

属性的MaxIdleTime默认值是创建 对象时ServicePoint属性的值ServicePointManager.MaxServicePointIdleTime。 对 属性的 MaxServicePointIdleTime 后续更改对现有 ServicePoint 对象没有影响。

MaxIdleTime当超过与 ServicePoint 关联的连接的 时,连接将保持打开状态,直到应用程序尝试使用该连接。 此时,框架将关闭连接,并创建与远程主机的新连接。

适用于