Điều này chỉ xảy ra trên một trong các máy của tôi. Tôi nghĩ rằng đó là một vấn đề cấu hình môi trường. Tất cả các máy chạy tường lửa phần mềm ESET Smart Security. Ý tưởng nào?DownloadStringAsync chặn chuỗi trong 14 giây trên lần gọi đầu tiên
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);
}
}
}
Điều này có thể là do Tự động phát hiện proxy. Mọi thay đổi nếu bạn đặt WebClient.Proxy thành GlobalProxySelection.GetEmptyWebProxy? http://msdn.microsoft.com/en-us/library/system.net.webclient.proxy.aspx http://msdn.microsoft.com/en-us/library/system.net.globalproxyselection.getemptywebproxy.aspx – dtb
Đúng, đã sửa nó. Cảm ơn! Cuộc gọi đầu tiên: 00: 00: 00.1680096 Cuộc gọi thứ hai: 00: 00: 00.0400023 – Mango
@dtb, thêm câu trả lời đó làm câu trả lời. Nó xứng đáng là một cuộc bỏ phiếu hoặc hai. –