WebRequest.Timeout プロパティ

定義

要求がタイムアウトするまでのミリ秒単位の時間を取得または設定します。

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

プロパティ値

要求がタイムアウトするまでの時間 (ミリ秒単位)、または要求がタイムアウトしないことを示す値 Infinite 。既定値は、子孫クラスによって定義されます。

例外

プロパティが派生クラスでオーバーライドされていないのに、そのプロパティの取得または設定が試行されました。

次の例では、 プロパティを Timeout 10000 ミリ秒に設定します。 リソースを返す前にタイムアウト期間が切れると、 WebException がスローされます。

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

注釈

プロパティは Timeout 、要求がタイムアウトして をスローするまでの時間の長さをミリ秒単位で WebException示します。 プロパティは Timeout 、 メソッドで GetResponse 行われた同期要求にのみ影響します。 非同期要求をタイムアウトにするには、 メソッドを使用します Abort

Note

クラスは WebRequest クラスです abstract 。 実行時のインスタンスの実際の WebRequest 動作は、 メソッドによって返される子孫クラスによって WebRequest.Create 決定されます。 既定値と例外の詳細については、 や などのHttpWebRequestFileWebRequest子孫クラスのドキュメントを参照してください。

注意 (継承者)

子孫クラスは、 フィールドを に設定して をWebExceptionスローすることでタイムアウトをTimeoutStatus通知します。 が にInfinite設定されている場合Timeout、子孫クラスはタイムアウトしません。

適用対象

こちらもご覧ください