473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

webclient timeout

i am a newbie, i want to write a code to download data from web using
webclient

string HTMLstring = "";

WebClient client = new WebClient();
Byte[] HP = client.DownloadData("http://www.microsoft.com");
HTMLstring = Encoding.ASCII.GetString(HP);
is it possible to add a timeout timer for this code, e.g. 10s
or i must use another class, like webrequest to doing so?

Thanks for your help!!
Aug 29 '07 #1
1 3921
In article <46********@127.0.0.1>, ma*****@yahoo.com.hk says...
i am a newbie, i want to write a code to download data from web using
webclient

string HTMLstring = "";

WebClient client = new WebClient();
Byte[] HP = client.DownloadData("http://www.microsoft.com");
HTMLstring = Encoding.ASCII.GetString(HP);
is it possible to add a timeout timer for this code, e.g. 10s
or i must use another class, like webrequest to doing so?
You could use DownloadDataAsync to run the command asynchornously (while
other code is running -- like a progress dialog that will wait 10
seconds). If the "DownloadDataCompleted" event is raised within the 10
seconds, you're good. Otherwise, you can use the CancelAsync method and
let the user know the request timed out.

--
Patrick Steele (pa*****@mvps.org)
http://weblogs.asp.net/psteele
Sep 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Kueishiong Tu | last post by:
I am using webclient to retrieve data from a web site. How do I control the time-out of this request?
6
by: genc ymeri | last post by:
Hi, We are struggeling to upload a file through a C# webClient into JBoss web server. Meanwhile we are able to upload a file from the webserver itself. The problem is only with C# webClient . The...
3
by: Michael Fields | last post by:
I have a problem with the WebClient and uploading a file to a web server. The stream object returned from the WebClient.OpenWrite menthod throws a timeout exception when using this method on...
2
by: Jon | last post by:
Hi using vb.net/vis studio 2003 Im using system net webclient to pull data from some other web sites, works well with 1 but - I'd like to be able to set a short timeout on the request. There...
2
by: Crirus | last post by:
How can I change a WebClient timeout in order to allow more time to a server to respond -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would take it...
1
by: Patrick Dugan | last post by:
I am using the webclient (system.net) to download a file. I haven't found a "timeout" interval setting so I'm guessing there must be some other way to limit it. Is there anyway to limit the amount...
4
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great...
0
by: Yet Another One | last post by:
Hello, I am using System.Net.WebClient() to download a web page. This works fine in itself, BUT... if there is no response from the web site or if my network is down, it NEVER times out trying...
1
by: jmk | last post by:
I'm trying to use an external SMS-service through .NET Framework 1.1 and using the webClient.DownloadData(strMessage) method. The strMessage is a string consisting the parameters to send a message,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.