By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,977 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,977 IT Pros & Developers. It's quick & easy.

webclient timeout

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.