Compartir a través de


ServicePoint.MaxIdleTime Propiedad

Definición

Obtiene o establece la cantidad de tiempo que una conexión asociada al objeto ServicePoint 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 objeto ServicePoint puede permanecer inactiva antes de que se cierre y se reutilice para otra conexión.

Excepciones

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

Ejemplos

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

// Display the date and time that the ServicePoint was last 
// connected to a host.
Console::WriteLine( "IdleSince = {0}", sp->IdleSince );

// 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 = {0}", 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);
' 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

Cautela

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

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

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

Cuando se supera el MaxIdleTime de una conexión asociada a un 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.

Se aplica a