c# – Windows服务中的一个ServiceProcessInstaller中的多个Serv
发布时间:2020-12-15 22:41:02 所属栏目:百科 来源:网络整理
导读:我在ServiceProcessInstaller中添加了两个ServiceInstallers.之后我改变了我的Main()如下: static void Main() { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1(),new Service2() }; ServiceBase.Run(ServicesToRun); }
我在ServiceProcessInstaller中添加了两个ServiceInstallers.之后我改变了我的Main()如下:
static void Main() { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1(),new Service2() }; ServiceBase.Run(ServicesToRun); } 我还在Service1上将Service2设置为依赖服务,如下所示: private void InitializeComponent() { this.Service1ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller(); this.Service1Installer = new System.ServiceProcess.ServiceInstaller(); this.Service2Installer = new System.ServiceProcess.ServiceInstaller(); // // Service1ProcessInstaller // this.Service1ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.Service1ProcessInstaller.Password = null; this.Service1ProcessInstaller.Username = null; // // Service1Installer // this.Service1Installer.ServiceName = "Service1"; this.Service1Installer.ServicesDependedOn = new string[] {"Service2"}; // // Service2Installer // this.Service2Installer.ServiceName = "Service2"; // // ProjectInstaller // this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.Service1ProcessInstaller,this.Service1Installer,this.Service2Installer}); } 它仍然只运行我的Service1. Service2永远不会打电话. 如果我在Main()中更改序列,则Service2仅调用. 它总是呼叫第一个服务. 如何拨打我的两项服务? 解决方法
我找到了解决方案.问题不在于卸载时的依赖服务.我已经卸载了我的服务然后再次安装它然后我在我的Services.msc中找到了这两个服务.
当它们实际上彼此依赖时我们需要依赖服务,所以我也删除了相关的服务代码. 现在我可以手动启动它们.它们都在运行.下面是我成功运行的代码. static void Main() { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1(),new Service2() }; ServiceBase.Run(ServicesToRun); } private void InitializeComponent() { this.Service1ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller(); this.Service1Installer = new System.ServiceProcess.ServiceInstaller(); this.Service2Installer = new System.ServiceProcess.ServiceInstaller(); // // Service1ProcessInstaller // this.Service1ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.Service1ProcessInstaller.Password = null; this.Service1ProcessInstaller.Username = null; // // Service1Installer // this.Service1Installer.ServiceName = "Service1"; // // Service2Installer // this.Service2Installer.ServiceName = "Service2"; // // ProjectInstaller // this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.Service1ProcessInstaller,this.Service2Installer}); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |