共用方式為


ServicePointManager.MaxServicePoints 屬性

定義

取得或設定要在任何時間維護 ServicePoint 物件的最大數。

public:
 static property int MaxServicePoints { int get(); void set(int value); };
public static int MaxServicePoints { get; set; }
static member MaxServicePoints : int with get, set
Public Shared Property MaxServicePoints As Integer

屬性值

要維護的 ServicePoint 物件最大數。 預設值為 0,這表示 ServicePoint 物件數沒有限制。

例外狀況

範例

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

// 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.
ServicePointManager::MaxServicePointIdleTime = 10000;
// 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;
' Set the maximum number of ServicePoint instances to maintain.
' Note that, 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. 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.
ServicePointManager.MaxServicePointIdleTime = 10000

備註

當您減少 MaxServicePoints 目前存在物件數目下方的屬性 ServicePoint 時,會 ServicePointManager 刪除 ServicePoint 具有最長空閒時間的物件。 如果作用中連接的物件數目 ServicePoint 大於 的值 MaxServicePoints,物件 ServicePointManager 就會 ServicePoint 在對象變成閑置時刪除物件。

適用於

另請參閱