ServicePoint.MaxIdleTime Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém ou define a quantidade de tempo em que uma conexão associada ao objeto pode permanecer ociosa ServicePoint antes que a conexão seja fechada.
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 da propriedade
O período de tempo, em milissegundos, que uma conexão associada ao objeto pode permanecer ociosa ServicePoint antes de ser fechada e reutilizada para outra conexão.
Exceções
MaxIdleTime é definido como menor Infinite ou maior que Int32.MaxValue.
Exemplos
O exemplo de código a seguir usa a MaxIdleTime propriedade para definir e recuperar o tempo ocioso 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()))
Comentários
Cuidado
WebRequest, HttpWebRequeste ServicePointWebClient são obsoletos e você não deve usá-los para um novo desenvolvimento. Use HttpClient em seu lugar.
Você pode definir MaxIdleTime para Timeout.Infinite indicar que uma conexão associada ao ServicePoint objeto nunca deve ter tempo limite.
O valor padrão da MaxIdleTime propriedade é o valor da ServicePointManager.MaxServicePointIdleTime propriedade quando o ServicePoint objeto é criado. As alterações subsequentes na MaxServicePointIdleTime propriedade não têm efeito sobre os objetos existentes ServicePoint .
Quando a MaxIdleTime conexão associada a uma ServicePoint for excedida, a conexão permanecerá aberta até que o aplicativo tente usar a conexão. Nesse momento, a Estrutura fecha a conexão e cria uma nova conexão com o host remoto.
Note
Desde o .NET 9, essa propriedade é mapeada para SocketsHttpHandler.PooledConnectionIdleTimeout. No entanto, os manipuladores não estão sendo reutilizados entre solicitações, portanto, ele não tem nenhum impacto significativo.