語言

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 = " + 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()))

備註

注意事項

WebRequest、、HttpWebRequest、ServicePointWebClient、和 都已過時,你不應該用它們來做新開發。 請改用 HttpClient。

你可以設定 MaxIdleTime 為 , Timeout.Infinite 表示與 ServicePoint 物件相關的連線永遠不會逾時。

屬性的MaxIdleTime預設值是物件建立時ServicePointManager.MaxServicePointIdleTime的ServicePoint屬性值。 後續對物業的變更 MaxServicePointIdleTime 不會影響現有 ServicePoint 物件。

當與 a MaxIdleTime 關聯的連線 超過 時ServicePoint,該連線會保持開啟狀態,直到應用程式嘗試使用該連線。 此時,Framework 會關閉連線,並建立一條新的連線給遠端主機。

Note

自 .NET 9 起,此屬性映射至 SocketsHttpHandler.PooledConnectionIdleTimeout。 然而,處理器並不會在請求間重複使用,因此沒有實質影響。

適用於