ServicePoint.IdleSince 屬性

定義

取得 ServicePoint 物件上次連接到主機的日期和時間。

C#
public DateTime IdleSince { get; }

屬性值

DateTime 物件,其中包含上次連接 ServicePoint 物件的日期和時間。

範例

下列程式代碼範例會使用 IdleSince 屬性來設定和擷取 ServicePoint 物件上次連接到主機的日期和時間。

C#
// 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);

備註

警告

WebRequestHttpWebRequestServicePointWebClient 已經過時,您不應該將它們用於新的開發。 請改用 HttpClient

IdleSince 屬性會記錄服務點與主機中斷連線的最後日期和時間。 當目前時間與 IdleSince 之間的差異超過 MaxIdleTime的值時,ServicePoint 物件可用來回收至另一個連接。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1