FileWebRequest.Timeout 屬性

定義

取得或設定要求逾時之前的時間長度。

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 (指出要求未逾時)。

例外狀況

指定的值小於或等於零,並且不是 Infinite

範例

下列程式代碼範例會 Timeout 設定 屬性。 請參閱 類別中 FileWebRequest 的完整範例。

// 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 秒的值,則擲回 之前 WebException 可能需要 15 秒以上的時間,以指出要求逾時。

適用於