Cela se produit uniquement sur l'une de mes machines. Je pense que c'est un problème de configuration de l'environnement. Toutes les machines exécutent le pare-feu du logiciel ESET Smart Security. Des idées?DownloadStringAsync bloque le fil pendant 14 secondes au premier appel
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);
}
}
}
Cela peut être dû à la détection automatique du proxy. Toute modification si vous définissez WebClient.Proxy sur 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
Oui, ça l'a corrigé. Merci! Premier appel: 00: 00: 00.1680096 Deuxième appel: 00: 00: 00.0400023 – Mango
@dtb, ajoutez cela comme réponse. Il mérite un vote ou deux. –