C#Web客户端的演技减缓第一次 [英] C# WebClient acting slow the first time

查看:155
本文介绍了C#Web客户端的演技减缓第一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Web客户端下载从网站的字符串(其中只包含纯文本,没有别的),所以我用了DownloadString方式:

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");

它工作正常,但问题在于,它第一次下载的字符串时,它需要很长的时间,比如5秒。之后,它的工作速度快。为什么会出现这种情况?如何解决这个问题?

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?

推荐答案

设置的代理属性的 Web客户端对象为null应该消除,你看到的延迟。另外,如果你已经配置你的系统使用代理服务器可以检索到 WebRequest.GetSystemWebProxy 。第二种方法应消除在这两种情况下的延迟。

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.

这篇关于C#Web客户端的演技减缓第一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆