FileWebRequest.Timeout FileWebRequest.Timeout FileWebRequest.Timeout FileWebRequest.Timeout Property

定义

获取或设置请求超时前的时间长度。Gets or sets the length of time until the request times out.

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

属性值

请求超时前的时间长度(以毫秒为单位),或是值 Infinite 以指示请求不超时。The time, in milliseconds, until the request times out, or the value Infinite to indicate that the request does not time out.

异常

指定的值小于或等于零,并且不为 InfiniteThe value specified is less than or equal to zero and is not Infinite.

示例

下面的代码示例设置Timeout属性。The following code example sets the Timeout property. 请参阅FileWebRequest类中的完整示例。Refer to the complete example in the FileWebRequest class.

// Create a Uri object.
Uri^ myUrl = gcnew Uri( String::Format( "file://{0}", fileName ) );

// Create a FileWebRequest object.
myFileWebRequest = dynamic_cast<FileWebRequest^>(WebRequest::CreateDefault( myUrl ));

// Set the timeout to the value selected by the user.
myFileWebRequest->Timeout = timeout;

// Create a Uri object. 
Uri myUrl = new Uri ("file://" + fileName);

// Create a FileWebRequest object.
myFileWebRequest = (FileWebRequest)WebRequest.CreateDefault (myUrl);

// Set the time-out to the value selected by the user.
myFileWebRequest.Timeout = timeout;

' Create a Uri object.to access the file requested by the user. 
Dim myUrl As New Uri("file://" + fileName)

' Create a FileWebRequest object.for the requeste file.
myFileWebRequest = CType(WebRequest.CreateDefault(myUrl), FileWebRequest)

' Set the time-out to the value selected by the user.
myFileWebRequest.Timeout = timeout

注解

域名系统 (DNS) 查询可能需要长达15秒钟的时间来返回或超时。如果你的请求包含需要解析的主机名, 并且你Timeout将其设置为小于15秒的值, 则可能需要15秒或更WebException长时间, 然后才会引发以指示请求超时。A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your request contains a host name that requires resolution and you set Timeout to a value less than 15 seconds, it may take 15 seconds or more before a WebException is thrown to indicate a time-out on your request.

适用于