.NET Windows Service - multiple services in one pr

2019-02-02 07:01发布

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?

3条回答
Anthone
2楼-- · 2019-02-02 07:13

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.

查看更多
beautiful°
3楼-- · 2019-02-02 07:25

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!

查看更多
Emotional °昔
4楼-- · 2019-02-02 07:35

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:

Can I have multiple services hosted in a single windows executable.

Thanks!

查看更多
登录 后发表回答