【发布时间】:2010-06-27 19:17:11
【问题描述】:
这只发生在我的一台机器上。我认为这是一个环境配置问题。所有计算机都运行 ESET Smart Security 软件防火墙。有什么想法吗?
using System;
using System.Net;
using System.Diagnostics;
using System.Threading;
namespace Test
{
static class Program
{
[STAThread]
static void Main()
{
bool exit = false;
WebClient wc = new WebClient();
DateTime before = DateTime.Now;
wc.DownloadStringAsync(new Uri("http://74.125.95.147"), "First"); // IP Address of google, so DNS requests don't add to time.
wc.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e)
{
Debug.WriteLine(e.UserState + " Call: " + (DateTime.Now - before));
if ((string)e.UserState == "First")
{
before = DateTime.Now;
wc.DownloadStringAsync(new Uri("http://74.125.95.147"), "Second");
}
else
exit = true;
};
/*
*
* Output:
*
* First Call: 00:00:13.7647873
* Second Call: 00:00:00.0740042
*
*/
while (!exit)
Thread.Sleep(1000);
}
}
}
【问题讨论】:
-
这可能是由于自动代理检测。如果将 WebClient.Proxy 设置为 GlobalProxySelection.GetEmptyWebProxy,有什么变化吗? msdn.microsoft.com/en-us/library/…msdn.microsoft.com/en-us/library/…
-
是的,解决了它。谢谢!第一次通话:00:00:00.1680096 第二次通话:00:00:00.0400023
-
@dtb,将其添加为答案。它值得一两票。