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

发布于 2024-08-10 11:34:46 字数 871 浏览 2 评论 0原文

我的问题与以下问题基本相同,但答案对我没有帮助。

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

本质上,我有 3 个服务,比如说“Service1”、“Service”和“Service3”。

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
                                {
                                    new Service1("Service1"),
                                    new Service2("Service2"),
                                    new Service3("Service3")
                                };

ServiceBase.Run(ServicesToRun);

我也有相应的安装程序类 其中每个服务的 serviceInstaller.ServiceName = "ServiceX"。

当我使用 installutil 时,我确实在服务管理器上看到了所有 3 个服务。但是,当我启动它们(其中任何一个或全部)时,只有第一个(“Service1”)正在运行。

我知道这是微不足道的,我可能可以为每个项目都有不同的安装程序项目,但就我而言,仅使用一个在语义上更有意义,

感谢您的帮助,

谢谢 维努

My question is essentially the same as the following one but the answer did not help me.

.NET Windows Service - multiple services in one project

Essentially, I have 3 services, lets say "Service1", "Service" and "Service3".

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
                                {
                                    new Service1("Service1"),
                                    new Service2("Service2"),
                                    new Service3("Service3")
                                };

ServiceBase.Run(ServicesToRun);

I also have installer classes with corresponding
serviceInstaller.ServiceName = "ServiceX" for each of these services.

When I use installutil, i do see all 3 services on the Service manager. However, when i start them (any or all of them) only the first one ("Service1") is running.

I know this is trivial and i can probably have different installer projects for each of these but in my case, it semantically makes more sense to use just one

Your help is appreciated

Thanks
Venu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-08-17 11:34:46

我创建了一个 3 服务项目(如下),它为每个服务使用一个项目安装程序。然后我添加了一个安装程序项目,它将服务安装到服务管理器中。我的工作流程如下:

  1. 在 Visual Studio 2008 的解决方案中创建 3 个服务。将每个服务命名为 Service1、Service2 和 Service3。 (确保将实际服务名称更改为属性窗口中各自的名称。)
  2. 向此解决方案添加了一个安装程序项目。
  3. 将三个服务项目的项目输出添加到安装程序项目中。
  4. 为安装程序中的所有三个服务添加了自定义操作,用于在服务管理器中安装服务。
  5. 建造并安装。

这在服务管理器中提供了三个不同的服务:Service1、Service2 和 Service3

享受吧!

http://code.google.com/p/multi-service-install/

编辑:

我已更新存储库中的代码以拥有一个可执行文件但有两个服务。每个服务都以自己的名称和启动/停止的能力安装到服务管理器中。我想这就是你想要的,对吧?这就是我所做的:

  1. 创建一个服务项目。
  2. 向同一项目添加了第二个服务(具有唯一的服务名称)。
  3. 向两个服务(ServiceA 和 ServiceB)添加了安装程序。
  4. 在 ProjectInstaller.Designer.vb 文件中,我更改了 Me.Installers.AddRange 行以显示两个服务安装程序。 (Me.ServiceInstaller1、Me.ServiceInstaller2)
  5. 在主服务(在我的例子中为 ServiceA)的 Main 入口点中,我将 ServicesToRun 变量设置为包含我希望其运行的所有服务(ServiceA 和 ServiceB)的 ServiceBase 数组。这是重要的一步,因为服务管理器根据此处的参数数量设置属性 - 要么允许同一 exe 的多个实例,要么只允许单个实例。
  6. 添加安装程序项目并使用服务的输出。
  7. 使用服务的输出添加自定义操作。

该代码仍然可以从上述相同的链接下载。

谢谢!

I created a 3 service project (below) which uses a project installer for each service. I then added an installer project which installs the services into service manager. Here was my workflow:

  1. Create 3 services in a solution in Visual Studio 2008. Naming each service as Service1, Service2 and, Service3. (Being sure to change the actual service names to their respective names in the properties window.)
  2. Added an Installer project to this solution.
  3. Added the project outputs from the three service projects to the installer project.
  4. Added custom actions for all three services in the installer for Installing the services in service manager.
  5. Built and Installed.

This gives me three distinct services in service manager: Service1, Service2 and Service3

Enjoy!

http://code.google.com/p/multi-service-install/

EDIT:

I have updated the code in the repository to have one executable but two services. Each service installs to the service manager with its own name and ability to start/stop. I think this is what you're wanting, correct? Here is what I did:

  1. Created a service project.
  2. Added a second service to the same project (with a unique service name).
  3. Added an installer to both services (ServiceA and ServiceB).
  4. In the ProjectInstaller.Designer.vb file I changed the Me.Installers.AddRange line to show both of the service installers. (Me.ServiceInstaller1, Me.ServiceInstaller2)
  5. In the Main entry point of the main service (ServiceA in my case), I set the ServicesToRun variable to an array of ServiceBase containing all the services that I want it to run (ServiceA and ServiceB). This is an important step as the service manager sets a property based on the number of arguments here - either to allow multiple instances of the same exe or only a single instance.
  6. Add an installer project and use the output of Services.
  7. Add a custom action using the output from Services.

The code can still be downloaded from the same link as above.

Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文