Take the 2-minute tour ×

Problem: This console app calls a long running webpage hosted on Azure twice. I want it to call it only once.

The console app fails with a caught exception: The underlying connection was closed: An unexpected error occurred on a receive. so question

If I call the page from Chrome, it runs once (as expected)

public class ExtendedWebClient : WebClient
    public int Timeout { get; set; }

    protected override WebRequest GetWebRequest(Uri address)
        HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
        if (request != null)
            request.Timeout = Timeout;
        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        return request;

    public ExtendedWebClient()
        Timeout = 1000000; // in ms.. the standard is 100,000

class Program
    static void Main(string[] args)
        var taskUrl = "http://secret.net/SendWeeklyEmails.aspx";
        // create a webclient and issue an HTTP get to our url
            using (ExtendedWebClient httpRequest = new ExtendedWebClient())
                var output = httpRequest.DownloadString(taskUrl);
        catch (Exception ex)
            Console.WriteLine("Exception was: " + ex.Message);
share|improve this question
@smarx - how did you find that duplicate? Just interested –  Exitos Jun 24 '11 at 6:20
Can you run fiddler and monitor the traffic to see whats going on? –  Exitos Jun 24 '11 at 6:20
@Pete2k I read everything with the "azure" tag, so I'd just seen it. :) –  smarx Jun 25 '11 at 4:35
I linked the duplicate in the question.. thought it may help people googling in the future, and tried to attack problem a different way. Appreciated everyone. Fiddler didn't work.. Wireshark gave me a clue to a possible keepalive by Chrome after 45secs. –  Dave Mateer Jun 27 '11 at 4:11

1 Answer 1

up vote 0 down vote accepted

Simple answer - I don't believe this client calls the page twice!

If your call is long running and Azure doesn't allow you to do long-polling, then you will need to rearchitect this app so that you have separate calls for starting and then progress monitoring this "SendWeeklyEmails" task. You could even do this using your command line client code, instead of using the web app.

share|improve this answer
Am going to close the question - yes a rearchitect as a console app is the way forward. Thanks. –  Dave Mateer Jul 10 '11 at 7:13

Your Answer


