Gets or sets the number of milliseconds after which an active ServicePoint connection is closed.
Assembly: System (in System.dll)
Property ValueType: System.Int32
A Int32 that specifies the number of milliseconds that an active ServicePoint connection remains open. The default is -1, which allows an active ServicePoint connection to stay connected indefinitely. Set this property to 0 to force ServicePoint connections to close after servicing a request.
The value specified for a set operation is a negative number less than -1.
You can use this property to ensure that a ServicePoint object's active connections do not remain open indefinitely. This property is intended for scenarios where connections should be dropped and reestablished periodically, such as load balancing scenarios.
By default, when KeepAlive is true for a request, the MaxIdleTime property sets the time-out for closing ServicePoint connections due to inactivity. If the ServicePoint has active connections, MaxIdleTime has no effect and the connections remain open indefinitely.
When the property is set to a value other than -1, and after the specified time elapses, an active ServicePoint connection is closed after servicing a request by setting KeepAlive to false in that request.
Setting this value affects all connections managed by the ServicePoint object.
The following code example sets the value of this property.
Imports System Imports System.Net Imports System.Net.Sockets Imports System.IO Imports System.Threading Public Class ServicePointExample ' Pass in the name of the Web page to retrieve. Public Shared Sub Main(ByVal args() As String) Dim page As String If args Is Nothing OrElse args.Length = 0 OrElse args(0).Length = 0 Then page = "http://www.contoso.com/default.html" Else page = args(0) End If Dim request As HttpWebRequest = CType(WebRequest.Create(page), HttpWebRequest) ' Get the service point that handles the request's socket connection. Dim point As ServicePoint = request.ServicePoint ' Set the receive buffer size on the underlying socket. point.ReceiveBufferSize = 2048 ' Set the connection lease timeout to infinite. point.ConnectionLeaseTimeout = Timeout.Infinite ' Send the request. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) Dim responseStream As Stream = response.GetResponseStream() Dim s As New StreamReader(responseStream) ' Display the response. Console.WriteLine(s.ReadToEnd()) responseStream.Close() response.Close() End Sub 'Main End Class
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2