WebRequest.Timeout Özellik

Tanım

İstek zaman aşımına uğramadan önce milisaniye cinsinden süreyi alır veya ayarlar.

public:
 virtual property int Timeout { int get(); void set(int value); };
public virtual int Timeout { get; set; }
member this.Timeout : int with get, set
Public Overridable Property Timeout As Integer

Özellik Değeri

İstek zaman aşımına uğradıysa milisaniye cinsinden süre veya isteğin zaman aşımına uğrmadığını belirten değer Infinite . Varsayılan değer, alt sınıf tarafından tanımlanır.

Özel durumlar

özelliği alt sınıfta geçersiz kılınmadığında özelliği almak veya ayarlamak için herhangi bir girişimde bulunulmaktadır.

Örnekler

Aşağıdaki örnek özelliği 10000 milisaniye olarak ayarlar Timeout . Kaynağın döndürülebilmesi için zaman aşımı süresi dolarsa, bir WebException oluşturulur.

// Create a new WebRequest Object to the mentioned URL.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );
Console::WriteLine( "\nThe Timeout time of the request before setting is : {0} milliseconds", myWebRequest->Timeout );

// Set the 'Timeout' property in Milliseconds.
myWebRequest->Timeout = 10000;

// This request will throw a WebException if it reaches the timeout limit
// before it is able to fetch the resource.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

         // Create a new WebRequest Object to the mentioned URL.
WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");
Console.WriteLine("\nThe Timeout time of the request before setting is : {0} milliseconds",myWebRequest.Timeout);

// Set the 'Timeout' property in Milliseconds.
myWebRequest.Timeout=10000;

// This request will throw a WebException if it reaches the timeout limit before it is able to fetch the resource.
         WebResponse myWebResponse=myWebRequest.GetResponse();

   ' Create a new WebRequest Object to the mentioned URL.
   Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")
   Console.WriteLine(ControlChars.Cr + "The Timeout time of the request before setting is : {0} milliseconds", myWebRequest.Timeout)

   ' Set the 'Timeout' property in Milliseconds.
myWebRequest.Timeout = 10000

  ' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
   Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

Açıklamalar

Timeout özelliği, istek zaman aşımına uğrana ve bir WebExceptionoluşturana kadar geçen süreyi milisaniye cinsinden gösterir. Timeout özelliği yalnızca yöntemiyle GetResponse yapılan zaman uyumlu istekleri etkiler. Zaman uyumsuz isteklerin zaman aşımına uğradıklarından emin olmak için yöntemini kullanın Abort .

Not

sınıfı WebRequest bir abstract sınıftır. Çalışma zamanında örneklerin WebRequest gerçek davranışı, yöntemi tarafından döndürülen alt sınıf tarafından WebRequest.Create belirlenir. Varsayılan değerler ve özel durumlar hakkında daha fazla bilgi için ve FileWebRequestgibi HttpWebRequest alt sınıfların belgelerine bakın.

Devralanlara Notlar

Alt sınıflar, alanı olarak ayarlanmış bir WebException oluşturarak zaman aşımı sinyali Status gönderir Timeout. Alt Timeout sınıfa Infinite ayarlandığında zaman aşımına uğradı.

Şunlara uygulanır

Ayrıca bkz.