DownloadStringAsync blocks the thread for 14 seconds on first call

This only happens on one of my machines. I think this is an environment configuration problem. All machines fire up ESET Smart Security software. 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);
        }
    }
}
+5
source share
1 answer

Your computer is configured to automatically detect a proxy server.

You can disable it here:

Screen shot

Alternatively, you can manually override the proxy server used by WebClient. Set the WebClient.Proxy property to nullto indicate that the proxy server should not be used. Any explicit proxy setting disables automatic proxy detection.

client.Proxy = null;

- , - .

+12

All Articles