Reputation: 2838
I'm using WebClient to download some text from a web-page, like this:
WebClient wc = new WebClient();
string str = wc.DownloadString("http://blah");
Now while it works absolutely fine, one problem I am facing with it is that the first time it initializes and downloads the string it's very slow - it takes approximately 5 seconds. After that it downloads the text within half a second.
Is there any way I could overcome this problem? I would really like it to be fast all the time so that it isn't annoying for the user.
I'm using C#.NET 4.0 if that matters.
Upvotes: 1
Views: 2191
Reputation: 15303
The following solution was taken from here
What you are seeing is caused by automatic proxy discovery. When the app starts, Initially we dicsover what proxy to use and then use that proxy or the proxy script for the subsequent requests. When you close the app, the script or the proxy infrastructure is gone and we have to do this again next time the app starts up.
You have a couple of choices.
You can turn off the automatic proxy by going into the IE settings and switching off the automatically detect proxy settings option. This is in Tools->Internet Options->Connections tab->LAN Settings button. Uncheck the Automatically detect settings.
if You can determine a static proxy server [trhat does not change dynamically its name] you can specify that proxy WebProxy wp = new WebProxy(,......);
WebClient.Proxy = wp;
Upvotes: 1