Sys.Net.WebRequest timeout Property
Gets or sets the time-out value for the Sys.Net.WebRequest instance.
Note
To get or set property values for client API properties, you must call property accessor methods that are named with the get_ and set_ prefixes. For example, to get or set a value for a property such as cancel, you call the get_cancel or set_cancel methods.
var timeout = MyWebRequest.get_timeout();
MyWebRequest.set_timeout(value);
Parameters
Term |
Definition |
---|---|
value |
The time interval in milliseconds. |
Return Value
The current Web request time-out value in milliseconds.
Exceptions
Exception type |
Condition |
---|---|
value must be a non-negative integer. |
Remarks
The timeout property represents the time interval that the network executor associated with the WebRequest instance waits before timing out the network request.
By setting a time-out interval, you can make sure that a pending network call returns control reliably, instead of waiting for the underlying network stack to time out the request. The network executor interprets a value of zero to mean that it is the responsibility of the underlying network stack to time out.
Example
The following example shows how to set and get the request time-out value. This code is part of a complete example found in the WebRequest class overview.
// This function gets and sets the
// Web request time out.
function WebRequestTimeout()
{
// Instantiate the WebRequest.
var wRequest = new Sys.Net.WebRequest();
// Set the request Url.
wRequest.set_url(getPage);
var defaultTimeout =
wRequest.get_timeout();
// Set request timeout to 100 msec.
wRequest.set_timeout(100);
var newTimeout =
wRequest.get_timeout();
alert("Default timeout: " + defaultTimeout);
alert("New timeout: " + newTimeout);
// Set the web request completed event handler,
// for processing return data.
wRequest.add_completed(OnWebRequestCompleted);
// Execute the request.
wRequest.invoke();
}
See Also
Reference
Sys.Net.WebRequestManager Class