1

I have an application which sends continuous data through serial port on click of go button and have hosted in IIS .

I have set Auto Start mode to "Always Running " which will restart my IIS automatically but restarting stops sending data through port as i need to click again on go button to start sending data .

Is there any setting where auto re-start of IIS will hit my Go method and sending data can be continuous through port without any interruption.

Cyril Durand
  • 15,834
  • 5
  • 54
  • 62
Alok Sharma
  • 85
  • 1
  • 5
  • Why don't you host this logic in a Windows Service? – CodeCaster Jun 21 '16 at 10:08
  • @CodeCaster I have already designed and developed in Web Application .Now the problem is of sending continuous data where IIS re-start makes a problem as re-starting needs to hit go method . can i code it in my .Net application this setting where re-starting IIS hits go method. – Alok Sharma Jun 21 '16 at 10:22
  • Well yeah but it's like asking [_"I bought a motorcycle to transport cows, now why can't I transport more than one?"_](http://i.imgur.com/IDRSi.jpg). Application pool recycles and restarts are the number one reason why you shouldn't host long-running (and especially forever-running) processes in a web server. You've picked the wrong tool for the job. – CodeCaster Jun 21 '16 at 10:25
  • Yup..I agree but to step up for resolution is there any setting in IIS , where re-start can hit my go method – Alok Sharma Jun 21 '16 at 10:36
  • Possible duplicate of [How to detect if the current application pool is winding up in IIS7.5 and Asp.Net 3.5+](http://stackoverflow.com/questions/3448839/how-to-detect-if-the-current-application-pool-is-winding-up-in-iis7-5-and-asp-ne) – CodeCaster Jun 21 '16 at 10:58

1 Answers1

0

In order to execute a method when the application pool starts, you could use the PreApplicationStartMethod attribute of System.Web assembly.

[assembly: PreApplicationStartMethod(
              typeof(Starter), 
              nameof(Starter.PreApplicationStartMethod))]

public class Starter 
{
    public static void PreApplicationStartMethod()
    {
         // startup code here
    }
}

With this attribute, each time the application pool recycles, this method will be called. Be aware that during recycle, the application pool starts before the end of the other application. See IIS Process Recycling overlap for more information.

Cyril Durand
  • 15,834
  • 5
  • 54
  • 62