httpresponserequest-timed-out

request.GetResponse() Timeout


Waker.cs

class Waker
{
    Timer timer;
    public Waker()
    {
        timer = null;
    }
    public void WakeUpApplicationPool(object obj)
    {
        string url = "http://www.example.com";
        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Program.LogToFile("WakeUpApplicationPool: " + response.StatusDescription);
            response.Close();
        }
        catch (Exception ex)
        {
            Program.LogToFile("WakeUpApplicationPool_Error: " + ex.ToString());
        }
    }
    public void Start()
    {
        TimerCallback callback = new TimerCallback(WakeUpApplicationPool);
        int DUE_TIME = 0; //The amount of time to delay before the callback parameter invokes its methods.
        int PERIOD = int.Parse(ConfigurationManager.AppSettings["WakerIntervalPeriod"]); //The time interval (miliseconds) between invocations of the methods referenced by callback
        timer = new Timer(callback, null, DUE_TIME, PERIOD);
    }
    public void Stop()
    {
        timer.Dispose();
    }

}

Program.cs:

static void Main(string[] args)
    {
        try
        {
            Waker waker = new Waker();
            waker.Start();
        }
        catch(Exception ex) 
        {
            LogToFile(ex.ToString());                
        }            
    }

Log file:

15 Apr 2015 18:29:39 - WakeUpApplicationPool: OK

15 Apr 2015 18:31:39 - WakeUpApplicationPool: OK

15 Apr 2015 18:33:59 - WakeUpApplicationPool_Error: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 205.144.171.35:80
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)

15 Apr 2015 18:35:39 - WakeUpApplicationPool: OK

15 Apr 2015 18:37:39 - WakeUpApplicationPool: OK

15 Apr 2015 18:41:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse()
   at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)

15 Apr 2015 18:43:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse()
   at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)

15 Apr 2015 18:45:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse()
   at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)

15 Apr 2015 18:47:18 - WakeUpApplicationPool_Error: System.Net.WebException: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse()
   at ConsoleReporting.Waker.WakeUpApplicationPool(Object obj)

The problem is:

  1. My code is not working after it hit the Timed Out error. But after I restart the Program.exe, it is working again but it hit the Timed Out error after 10 minutes.
  2. I want to use this Program.exe to wake up my application pool which hosted at hosting provider.
  3. So could anyone tell the reason and solution is? I referred this,but it is not working for my code either

Solution

  • The problem is solved after I set the WakerIntervalPeriod to 10 minutes instead of 5 minuets.