这种情况只发生在我的一台机器上。我认为是环境配置问题。所有计算机均运行 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 使用的代理。设置WebClient.Proxy 属性 http://msdn.microsoft.com/en-us/library/system.net.webclient.proxy.aspx to null
指定不应使用代理。任何显式代理设置都会禁用自动代理检测。
client.Proxy = null;
但是,在这种情况下,您应该为用户提供在应用程序中配置代理的选项,因为某些用户在访问 Web 时需要使用代理。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)