我已将两个 ServiceInstaller 添加到我的 ServiceProcessInstaller。之后我改变了我的 Main() 如下:
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1(),
new Service2()
};
ServiceBase.Run(ServicesToRun);
}
我还将 Service2 设置为 Service1 的依赖服务,如下所示:
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 只会调用。
它总是调用第一个服务。
如何调用我的两种服务?