Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

Setting timeout property for System.Net.WebClient Class

, 20 Jun 2011
Rate this:
Please Sign up or sign in to vote.
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:

...
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)

Share

About the Author

nerdpro
Database Developer APN
New Zealand New Zealand
I am a database administrator for APN Holdings Ltd (NZ)

Comments and Discussions

 
GeneralWould this suffice? Pinmembernerdpro19-Jun-11 17:01 
GeneralI'm going to approve this, but a code snippet would be nice. PinsubeditorIndivara19-Jun-11 15:12 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 20 Jun 2011
Article Copyright 2011 by nerdpro
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid