views:

623

answers:

3

Currently, I have a project with a Windows Service. I also created another "Setup Project" which installs the Windows Service.

My question is this: Can I add another Windows Service to the same project? (This way, I can use 1 installer, and share some code between the services more easily.) If I can, does that mean when one service encounters errors then both services are stopped, or do they error out independently of each other?

Are there any other differences between coding 1 service per project, or having multiple services in one project?

+1  A: 

yes, you can have multiple services in the same project. Although they both use the same exe, they are loaded into different memory spaces and act independently of each other.

Kevin
So: same installation, but separate error handling as well? Would the only benefit to separating them out into different projects be that you could install one without the other?
Boris
If you have different processes that need to run and don't affect each other. You can turn on service off while leaving the other one on. We have services which share some of the same code, but have different functions and run at different intervals. By separating them we didn't have to worry about handling separate threads. It's not necessarily useful for every scenario, but it is possible.
Kevin
A: 

Hey Boris,

I know this is already answered, but if you'd like an example (code) of how to run two services in the same project please have a look at my answer to a similar question:

http://stackoverflow.com/questions/1688275/can-i-have-multiple-services-hosted-in-a-single-windows-executable/1688702#1688702.

Thanks!

Scott
+1  A: 

Hi! I am a developer for an open source windows service hosting framework called Daemoniq. Running multiple services in one process is one of its features. You can download it from http://daemoniq.org

Current features include:

  • container agnostic service location via the CommonServiceLocator
  • set common service properties like serviceName, displayName, description and serviceStartMode via app.config
  • run multiple windows services on the same process
  • set recovery options via app.config
  • set services depended on via app.config
  • set service process credentials via command-line
  • install, uninstall, debug services via command-line

Thanks!

jake.stateresa