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 オブジェクトに関連付けられた接続が閉じられ、別の接続に再利用されるまでのアイドル状態を維持できる時間 (ミリ秒単位)。

例外

MaxIdleTimeInfinite より小さいか 、Int32.MaxValue より大きい値に設定されます。

次のコード例では、 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()))

注釈

Caution

WebRequestHttpWebRequestServicePointWebClient は廃止されており、新しい開発には使用しないでください。 HttpClient を代わりに使用します。

MaxIdleTimeTimeout.Infinite に設定して、ServicePoint オブジェクトに関連付けられている接続がタイムアウトにならないように指定できます。

MaxIdleTime プロパティの既定値は、ServicePoint オブジェクトの作成時のServicePointManager.MaxServicePointIdleTime プロパティの値です。 MaxServicePointIdleTime プロパティに対する後続の変更は、既存のServicePoint オブジェクトには影響しません。

ServicePointに関連付けられている接続のMaxIdleTimeを超えた場合、アプリケーションが接続の使用を試みるまで、接続は開いたままです。 その時点で、フレームワークは接続を閉じ、リモート ホストへの新しい接続を作成します。

Note

.NET 9 以降、このプロパティは SocketsHttpHandler.PooledConnectionIdleTimeoutにマップされます。 ただし、ハンドラーは要求間で再利用されないため、意味のある影響はありません。

適用対象