ServicePointManager.MaxServicePointIdleTime 屬性

定義

取得或設定 ServicePoint 物件的最大閒置時間。

C#
public static int MaxServicePointIdleTime { get; set; }

屬性值

ServicePoint 物件的最大閒置時間,以毫秒為單位。 預設值為 100,000 毫秒 (100 秒)。

例外狀況

範例

下列程式代碼範例會設定這個屬性。

C#
// Set the maximum number of ServicePoint instances to
// maintain. If a ServicePoint instance for that host already
// exists when your application requests a connection to
// an Internet resource, the ServicePointManager object
// returns this existing ServicePoint instance. If none exists
// for that host, it creates a new ServicePoint instance.
ServicePointManager.MaxServicePoints = 4;

// Set the maximum idle time of a ServicePoint instance to 10 seconds.
// After the idle time expires, the ServicePoint object is eligible for
// garbage collection and cannot be used by the ServicePointManager object.
ServicePointManager.MaxServicePointIdleTime = 10000;

備註

屬性MaxServicePointIdleTime會設定物件在建立ServicePoint物件時指派給MaxIdleTime屬性的最大空閒時間ServicePointManager。 對此值所做的變更只會 ServicePoint 影響值變更之後初始化的物件。

ServicePoint物件在 中指定的MaxIdleTime時間閑置之後,它就有資格進行垃圾收集。 ServicePoint當與 對象相關聯的ServicePoint連接清單是空的時,物件就會閑置。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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

另請參閱