ServicePoint.MaxIdleTime Propiedad

Definición

Obtiene o establece la cantidad de tiempo que una conexión asociada al ServicePoint objeto puede permanecer inactiva antes de que se cierre la conexión.

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

Valor de propiedad

El período de tiempo, en milisegundos, que una conexión asociada al ServicePoint objeto puede permanecer inactiva antes de que se cierre y reutilice para otra conexión.

Excepciones

MaxIdleTime se establece en menor o Infinite mayor que Int32.MaxValue.

Ejemplos

En el ejemplo de código siguiente se usa la MaxIdleTime propiedad para establecer y recuperar el ServicePoint tiempo de inactividad.

// 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()))

Comentarios

Caution

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Utilice HttpClient en su lugar.

Puede establecer en MaxIdleTimeTimeout.Infinite para indicar que una conexión asociada al ServicePoint objeto nunca debe agotar el tiempo de espera.

El valor predeterminado de la MaxIdleTime propiedad es el valor de la ServicePointManager.MaxServicePointIdleTime propiedad cuando se crea el ServicePoint objeto. Los cambios posteriores en la MaxServicePointIdleTime propiedad no tienen ningún efecto en los objetos existentes ServicePoint .

Cuando se supera para MaxIdleTime una conexión asociada a , ServicePoint la conexión permanece abierta hasta que la aplicación intenta usar la conexión. En ese momento, framework cierra la conexión y crea una nueva conexión al host remoto.

Note

Desde .NET 9, esta propiedad se asigna a SocketsHttpHandler.PooledConnectionIdleTimeout. Sin embargo, los controladores no se reutilizan entre solicitudes, por lo que no tiene ningún impacto significativo.

Se aplica a