共用方式為


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

適用於