Click here to Skip to main content
15,867,453 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Setting timeout property for System.Net.WebClient Class

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
20 Jun 2011CPOL 24.6K   2
You can also use the System.Net.HttpWebRequest implementation of System.Net.WebRequest. It comes packaged with a timeout property - http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx.It would be a simple call to the object:...using System.Net;...HttpWebRequest...

You can also use the System.Net.HttpWebRequest implementation of System.Net.WebRequest. It comes packaged with a timeout property - http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx.


It would be a simple call to the object:


C#
...
using System.Net;

...

HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(new Uri("www.microsoft.com"));
webRequest.Timeout = 10000; // setting timeout value to 10 secs

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

// you may now use a stream reader to read the response stream

...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Database Developer APN
New Zealand New Zealand
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
GeneralI'm going to approve this, but a code snippet would be nice. Pin
Indivara19-Jun-11 15:12
professionalIndivara19-Jun-11 15:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.