C# WebClient 第一次运行缓慢

标签 c# .net performance download webclient

我正在使用 WebClient 从网站下载字符串(仅包含纯文本,没有其他内容),因此我使用 DownloadString 方法:

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

它工作正常,但问题是第一次下载字符串需要很长时间,比如 5 秒。之后它工作得很快。为什么会发生这种情况,如何克服这个问题?

最佳答案

WebClient 对象的 Proxy 属性设置为 null 应该可以消除您看到的延迟。或者,如果您已将系统配置为使用代理,则可以使用 WebRequest.GetSystemWebProxy 检索它。第二种方法应该消除两种情况下的延迟。

关于C# WebClient 第一次运行缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4932541/

相关文章:

c# - Windows Azure 服务总线队列 - MessageSender 还是 QueueClient?

c# - XML 反序列化为列表

c# - 将数据 URI 设置为 asp :Image in code behind using ASP.Net 和 C#

c# - 在 Mac 上使用 C#/Mono 的仅系统托盘(无停靠图标)应用程序

c# - 转换字典<int, List<User>>

performance - 用于Elasticsearch的模拟EXPLAIN MySql

c# - 为什么此 SQL INSERT 失败而没有引发异常?

c# - Excel 插件 - 注销时未调用 OnDisconnection/OnBeginShutdown

performance - jmeter Ant 构建错误。未找到 TestPlan 类

Nodejs 中 url.parse 的性能