Reputation: 60892
using (var client = new WebClient())
{
html = client.DownloadString(some_string);
//do something
html = client.DownloadString(some_string1);
//do something
html = client.DownloadString(some_string2);
//do something
html = client.DownloadString(some_string3);
//do something
etc
}
webclient does not allow itself enough time to download the entire source of the webpage. how do i force it to wait until it finishes the donwload?
Upvotes: 1
Views: 187
Reputation: 52952
DownloadString is a blocking call, so there is no need to do anything. It will continue to download until the string is received.
The problem probably lies in the fact that you shouldn't be using DownloadString. What are you trying to retrieve? Do you end up with half of your expected string?
You should probably use it as the MSDN article shows:
WebClient client = new WebClient ();
// Add a user agent header in case the
// requested URI contains a query.
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead (some_string);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
Console.WriteLine (s);
data.Close ();
reader.Close ();
The source is here: http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx
Upvotes: 2
Reputation: 4648
The web client doesn't allow programmatic access to Timeout. You'll have to use a HttpRequest object instead.
Upvotes: 1