我在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}); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。