Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using a WebClient to download a string from a website (which just contains plain text, nothing else), so I use the DownloadString method:

WebClient wc = new WebClient();
string str = wc.DownloadString("http://blah");

It works fine, but the problem is that the first time it downloads the string it takes a long time, like 5 seconds. After that it works fast. Why does this happen and how can overcome this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
527 views
Welcome To Ask or Share your Answers For Others

1 Answer

Setting the Proxy property of your WebClient object to null should eliminate the delays you're seeing. Alternatively if you've configured your system to use a proxy it can be retrieved with WebRequest.GetSystemWebProxy. The second method should eliminate the delay in either case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...