tags:

views:

47

answers:

1

This only happens on one of my machines. I think it's an environment configuration problem. All machines run ESET Smart Security software firewall. Any ideas?

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);
        }
    }
}
+3  A: 

If you experience a delay on the first call of a WebClient/HttpWebRequest related call, the reason might be Automatic Proxy Detection.

Set WebClient.Proxy to GlobalProxySelection.GetEmptyWebProxy to specify that no proxy should be used. Any explicit proxy setting disables Automatic Proxy Detection.

dtb
Since GlobalProxySelection is deprecated just set Proxy to nullAlso, to do this globally, WebRequest.DefaultWebProxy = null;
Mango