0

I wrote a code to call doMethod() every 2 minutes with System.Timers.Timer, the doMethod() use a web service on server A, but if the server A or IIS on the server A stops, after the reboot, doMethod() does not work. my questions are:

  1. does timer stops after the server rebooting? (I know the answer is no, but I'm confused)
  2. does the web service can't login or what, after the server rebooting?

here is the code :

public Form1()
    {
      InitializeComponent();

      System.Timers.Timer timer = new System.Timers.Timer
         {
           Interval = 120000 //2 minutes
         };

         timer.Elapsed += timer_Elapsed;
         timer.Start();
    }

private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
      var session = new WebApiLoginSession("http://172.27.1.1", "webserviceUser", "somePassword");

      if (string.IsNullOrEmpty(session.ID))
        {
          doMethod();
        }
    }
Nima Derakhshanjan
  • 1,380
  • 9
  • 24
  • 37
  • 1
    Your service will start only after it receives first request. It's default behavior of apps in IIS. Of course you can change that in app configuration. Here is link that might help [auto start app in IIS](https://stackoverflow.com/questions/34634659/how-to-properly-autostart-an-asp-net-application-in-iis10). – Arthur Sep 30 '19 at 06:16
  • 1
    How do you know its the server being rebooted or IIS recycling? What happens when the app stops working and you manually login to the WebApiLoginSession? – Jeremy Thompson Sep 30 '19 at 06:34
  • @JeremyThompson my application is inserting some data in SQL Server on the server A, and the other team are working on server A, and sometimes they have to reboot the server and before that they call me, but after rebooting the server, my application does not work until I restart the application. – Nima Derakhshanjan Sep 30 '19 at 06:39
  • Ok, my initial thought that the web service is cold and on first request loads libraries and if this takes > 1min it times out. What's the error you see? Does warming IIS after a reboot make a difference? When you say doMethod() doesn't work, how does it fail? – Jeremy Thompson Sep 30 '19 at 07:13
  • Thank you for your response. Well, warming up does not make any difference, cause I wait for more than 30 minutes, but still the application does not work. And it just show an error that the login was not successful and also I can't trace that because if I run the app for tracing, problem will disappear ... – Nima Derakhshanjan Sep 30 '19 at 07:37
  • @JeremyThompson actually I find that, while server A is down, web service tries to login, but login is not successful and after that application stops till manual restart ! – Nima Derakhshanjan Sep 30 '19 at 08:25
  • 1
    You'd have to check the code in `WebApiLoginSession` call why it fails? How could the creds be invalid? Does the service cut connections or more likely it's somehow orphaning them? – Jeremy Thompson Sep 30 '19 at 10:01

0 Answers0