4

Is it possible to host a long-running worker inside ASP.NET application? The worker (for it's a windows service) is reading from a queue sending messages to a WCF service. Would it be possible to run this "light long-running worker" inside an ASP.NET application? I read about setting pool start mode to "always running" and then using an AppStart class, which starts the worker.

I would like to get rid of the windows service (deployments and debugging problems) and embed this work inside IIS. Any suggestion?

7

It is indeed possible to do what you describe- I am currently working on an application that uses the Asp.Net Auto-start feature to have a worker thread behaving like a windows service but hosted inside IIS so you keep all your code in one place.

It is very handy and after the somewhat fiddly configuration it seems to work more or less as advertised although running a service in IIS rather than as a Windows service does have a slight impact on reliability in my ( non scientifically validated ) opinion. Certainly a useful tool, however and something that will only get better as it becomes more popular.

Edit: After a couple more months of using this configuration, it becomes clear that it will sometimes behave in slightly curious ways - for example starting multiple instances of the same thread - and it can generally be a little quirky. It also isn't necessarily any easier to troubleshoot than a regular windows service, although it probably is easier to deploy. On the application I am working with, we are looking at moving our long-running services from IIS to Windows Services.

  • How about stopping the worker when application is stopping? – redman Apr 16 '13 at 6:41
  • The worker runs in the application pool of your ASP.Net application, so it stops and starts along with that app pool. – glenatron Apr 16 '13 at 10:23
  • But can you handle the STOP event? If yes, how? – redman Apr 16 '13 at 12:40
  • I haven't needed to do it, from what I can tell the only extra thing you get from the IProcessHostPreloadClient interface is a Preload, I don't see anything about catching STOP events or even whether those are a thing that might be catchable. – glenatron Apr 16 '13 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.