ServicePoint.ConnectionLeaseTimeout Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Etkin ServicePoint bağlantının kapatıldığı milisaniye sayısını alır veya ayarlar.
public:
property int ConnectionLeaseTimeout { int get(); void set(int value); };
public int ConnectionLeaseTimeout { get; set; }
member this.ConnectionLeaseTimeout : int with get, set
Public Property ConnectionLeaseTimeout As Integer
Özellik Değeri
Int32 Etkin ServicePoint bir bağlantının açık kalacağı milisaniye sayısını belirten bir. Varsayılan değer -1'dir ve bu da etkin ServicePoint bir bağlantının süresiz olarak bağlı kalmasını sağlar. bir isteğe hizmet verdikten sonra bağlantıların kapanmasını zorlamak ServicePoint için bu özelliği 0 olarak ayarlayın.
Özel durumlar
Bir küme işlemi için belirtilen değer-1'den küçük negatif bir sayıdır.
Örnekler
Aşağıdaki kod örneği bu özelliğin değerini ayarlar.
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::IO;
using namespace System::Threading;
namespace SystemNetExamples
{
public ref class ServicePointExample
{
public:
// Pass in the name of the Web page to retrieve.
static void PrintResponse(String^ page)
{
// Create the request.
HttpWebRequest^ request;
Uri^ uri;
try
{
uri = gcnew Uri(page);
}
catch (UriFormatException^ ex)
{
Console::WriteLine(ex->Message);
}
request = (HttpWebRequest^) WebRequest::Create(uri);
// Get the service point that handles the request's
// socket connection.
ServicePoint^ point = 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.
HttpWebResponse^ response =
(HttpWebResponse^) request->GetResponse();
Stream^ responseStream = response->GetResponseStream();
StreamReader^ streamReader =
gcnew StreamReader(responseStream);
try
{
// Display the response.
Console::WriteLine(streamReader->ReadToEnd());
responseStream->Close();
response->Close();
}
finally
{
streamReader->Close();
}
}
};
}
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
namespace Examples.System.Net
{
public class ServicePointExample
{
// Pass in the name of the Web page to retrieve.
public static void Main(string[] args)
{
string page;
if (args == null || args.Length == 0 || args[0].Length == 0)
{
page = "http://www.contoso.com/default.html";
}
else
{
page = args[0];
}
// Create the request.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(page);
// Get the service point that handles the request's socket connection.
ServicePoint point = 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.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader s = new StreamReader(responseStream);
// Display the response.
Console.WriteLine(s.ReadToEnd());
s.Close();
responseStream.Close();
response.Close();
}
}
}
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
End Class
Açıklamalar
Nesnenin etkin bağlantılarının ServicePoint süresiz olarak açık kalmamasını sağlamak için bu özelliği kullanabilirsiniz. Bu özellik, yük dengeleme senaryoları gibi bağlantıların belirli aralıklarla bırakılması ve yeniden kurulması gereken senaryolara yöneliktir.
Varsayılan olarak, bir istek için olduğunda KeepAlivetrue
, MaxIdleTime özellik etkin olmama nedeniyle bağlantıların kapatılması ServicePoint için zaman aşımını ayarlar. ServicePoint etkin bağlantıları varsa, MaxIdleTime hiçbir etkisi yoktur ve bağlantılar süresiz olarak açık kalır.
ConnectionLeaseTimeout özelliği -1 dışında bir değere ayarlandığında ve belirtilen süre geçtikten sonra, etkin bir ServicePoint bağlantı, istekte olarak ayarlanarak KeepAlivefalse
isteğe hizmet verdikten sonra kapatılır.
Bu değerin ayarlanması nesne tarafından ServicePoint yönetilen tüm bağlantıları etkiler.
Şunlara uygulanır
Ayrıca bkz.
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin