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()))

注解

谨慎

WebRequestHttpWebRequestServicePointWebClient 已过时,不应将其用于新开发。 请改用 HttpClient

可以将 MaxIdleTime 设置为 Timeout.Infinite,以指示与 ServicePoint 对象关联的连接不应超时。

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

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

适用于