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 之連線的 時,連線會保持開啟狀態,直到應用程式嘗試使用連線為止。 此時,Framework 會關閉連線,並建立與遠端主機的新連線。

適用於