本文介绍了WebClient.DownloadString需要约15秒首次调用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string url = "http://google.com/index.html";
WebClient client = new WebClient();
Stopwatch sw = new Stopwatch();
sw.Start();
string text = client.DownloadString(url);
sw.Stop();
Console.WriteLine(sw.Elapsed);
秒表说 DownloadString
方法以13-15当第一秒调用,但多次呼吁采取明智的大量时间。这是如何发生,如何解决这个问题?
Stopwatch says DownloadString
method takes 13-15 seconds when first called, but repeated calls take sensible amounts of time. How does this happen and how do I fix it?
推荐答案
有可能是一对夫妇的事情,会导致对延迟第一个电话如检测代理设置。尝试将代理设置为null:
There may be a couple of things that would cause a delay on the first call such as detecting proxy settings. Try setting the proxy to null:
client.Proxy = null;
这篇关于WebClient.DownloadString需要约15秒首次调用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!