Editare

Partajați prin


ServicePoint.MaxIdleTime Property

Definition

Gets or sets the amount of time a connection associated with the ServicePoint object can remain idle before the connection is closed.

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

Property Value

The length of time, in milliseconds, that a connection associated with the ServicePoint object can remain idle before it is closed and reused for another connection.

Exceptions

MaxIdleTime is set to less than Infinite or greater than Int32.MaxValue.

Examples

The following code example uses the MaxIdleTime property to set and retrieve the ServicePoint idle time.

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

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

You can set MaxIdleTime to Timeout.Infinite to indicate that a connection associated with the ServicePoint object should never time out.

The default value of the MaxIdleTime property is the value of the ServicePointManager.MaxServicePointIdleTime property when the ServicePoint object is created. Subsequent changes to the MaxServicePointIdleTime property have no effect on existing ServicePoint objects.

When the MaxIdleTime for a connection associated with a ServicePoint is exceeded, the connection remains open until the application tries to use the connection. At that time, the Framework closes the connection and creates a new connection to the remote host.

Applies to