共用方式為


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 會關閉連線,並建立與遠端主機的新連線。

適用於