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

编程入门 行业动态 更新时间:2024-10-20 16:13:26
本文介绍了我可以在单个 Windows 可执行文件中托管多个服务吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

基本上,我有 3 个服务,比如说Service1"、Service"和Service3".

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);

我也有相应的安装程序类serviceInstaller.ServiceName = "ServiceX" 用于这些服务中的每一个.

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

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

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

感谢您的帮助

谢谢维努

推荐答案

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

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:

  • 在 Visual Studio 2008 的解决方案中创建 3 个服务.将每个服务命名为 Service1、Service2 和 Service3.(确保在属性窗口中将实际服务名称更改为各自的名称.)
  • 向此解决方案添加了安装程序项目.
  • 将三个服务项目的项目输出添加到安装程序项目中.
  • 在安装程序中为所有三个服务添加了自定义操作,以便在服务管理器中安装服务.
  • 构建并安装.
  • 这在服务管理器中为我提供了三个不同的服务:Service1、Service2 和 Service3

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

    code.google/p/multi-service-install/

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

    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:

  • 创建了一个服务项目.
  • 向同一个项目添加了第二个服务(具有唯一的服务名称).
  • 为两个服务(ServiceA 和 ServiceB)添加了一个安装程序.
  • 在 ProjectInstaller.Designer.vb 文件中,我更改了 Me.Installers.AddRange 行以显示两个服务安装程序.(Me.ServiceInstaller1, Me.ServiceInstaller2)
  • 在主服务(在本例中为 ServiceA)的 Main 入口点中,我将 ServicesToRun 变量设置为包含我希望它运行的所有服务(ServiceA 和 ServiceB)的 ServiceBase 数组.这是重要的一步,因为服务管理器根据此处的参数数量设置属性 - 允许同一 exe 的多个实例或仅允许单个实例.
  • 添加安装程序项目并使用服务的输出.
  • 使用服务的输出添加自定义操作.
  • 代码仍然可以从与上面相同的链接下载.

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

    谢谢!

    更多推荐

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

    本文发布于:2023-11-17 08:32:12,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609469.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:多个   可执行文件   Windows

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!