gpt4 book ai didi

c# - DownloadStringAsync 在第一次调用时阻塞线程 14 秒

转载 作者:太空狗 更新时间:2023-10-29 21:07:12 25 4
gpt4 key购买 nike

这只发生在我的一台机器上。我认为这是一个环境配置问题。所有机器运行 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);
}
}
}

最佳答案

您的机器配置为执行自动代理检测

你可以在这里禁用它:

Screenshot

或者,您可以手动覆盖 WebClient 使用的代理。设置 WebClient.Proxy Propertynull 以指定不应使用任何代理。任何明确的代理设置都会禁用自动代理检测。

client.Proxy = null;

但是,在这种情况下,您应该为用户提供在您的应用程序中配置代理的选项,因为某些用户在访问 Web 时需要使用代理。

关于c# - DownloadStringAsync 在第一次调用时阻塞线程 14 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3128563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com