C# .NET Windows 服务 - 一个项目中的多个服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1407217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 16:11:41  来源:igfitidea点击:

.NET Windows Service - multiple services in one project

c#.netwindowsservice

提问by

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

目前,我有一个带有 Windows 服务的项目。我还创建了另一个安装 Windows 服务的“安装项目”。

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?

我的问题是:我可以向同一个项目添加另一个 Windows 服务吗?(这样,我可以使用 1 个安装程序,并且可以更轻松地在服务之间共享一些代码。)如果可以,这是否意味着当一个服务遇到错误时,两个服务都会停止,还是它们彼此独立地出错?

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

每个项目编码 1 个服务或在一个项目中拥有多个服务之间是否还有其他区别?

采纳答案by kemiller2002

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.

是的,您可以在同一个项目中拥有多个服务。虽然它们都使用同一个exe文件,但是它们被加载到不同的内存空间并且相互独立地运行。

回答by Scott

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.

我可以在单个 Windows 可执行文件中托管多个服务吗

Thanks!

谢谢!

回答by jake.stateresa

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

我是一个名为 Daemoniq 的开源 Windows 服务托管框架的开发人员。在一个进程中运行多个服务是其功能之一。你可以从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
  • 通过 CommonServiceLocator 的容器不可知服务位置
  • 通过 app.config 设置公共服务属性,如 serviceName、displayName、description 和 serviceStartMode
  • 在同一进程上运行多个 Windows 服务
  • 通过 app.config 设置恢复选项
  • 通过 app.config 设置依赖的服务
  • 通过命令行设置服务进程凭据
  • 通过命令行安装、卸载、调试服务

Thanks!

谢谢!