Bagikan melalui


WebRequest.Timeout Properti

Definisi

Mendapatkan atau mengatur lamanya waktu, dalam milidetik, sebelum waktu permintaan habis.

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

Nilai Properti

Lamanya waktu, dalam milidetik, hingga waktu permintaan habis, atau nilai Infinite untuk menunjukkan bahwa permintaan tidak kehabisan waktu. Nilai default ditentukan oleh kelas turunan.

Pengecualian

Setiap upaya dilakukan untuk mendapatkan atau mengatur properti, ketika properti tidak ditimpa di kelas turunan.

Contoh

Contoh berikut mengatur Timeout properti menjadi 10000 milidetik. Jika periode batas waktu berakhir sebelum sumber daya dapat dikembalikan, WebException akan dilemparkan.

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

Keterangan

Properti Timeout menunjukkan lamanya waktu, dalam milidetik, sampai waktu permintaan habis dan melempar WebException. Properti Timeout hanya memengaruhi permintaan sinkron yang dibuat dengan GetResponse metode . Untuk mengeluarkan waktu permintaan asinkron, gunakan Abort metode .

Catatan

Kelasnya WebRequest adalah kelas abstract . Perilaku WebRequest aktual instans pada durasi ditentukan oleh kelas turunan yang dikembalikan oleh WebRequest.Create metode . Untuk informasi selengkapnya tentang nilai dan pengecualian default, lihat dokumentasi untuk kelas turunan, seperti HttpWebRequest dan FileWebRequest.

Catatan Bagi Inheritor

Kelas turunan memberi sinyal batas waktu dengan melempar WebException dengan bidang diatur Status ke Timeout. Ketika Timeout diatur ke Infinite kelas turunan tidak kehabisan waktu.

Berlaku untuk

Lihat juga