2017-01-06 15 views
3

私はServiceProcessInstallerに2つのServiceInstallerを追加しました。その後、私は以下のように私のメインを()に変更haved:まだそれは私のサービス1を実行している複数のServiceInstallerがWindowsサービスの1つのServiceProcessInstallerにあります

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

    } 

私も以下のようにサービス1に依存してサービスとしてサービス2を設定している
static void Main() 
    { 
     ServiceBase[] ServicesToRun; 
     ServicesToRun = new ServiceBase[] 
     { 
      new Service1(), 
      new Service2()     
     }; 
     ServiceBase.Run(ServicesToRun); 
    } 

Service2は決して呼び出しません。

Main()のシーケンスを変更した場合、Service2は呼び出すだけです。

常に最初のサービスを呼び出しています。

私の両方のサービスに電話するには?

+0

'services.msc'を開くと、そこに2つのサービスがありますか? – zaitsman

+0

@zaitsmanいいえ、私は持っていません。それはmyService.exe –

答えて

0

解決策が見つかりました。私のサービスをアンインストールしてからもう一度インストールした後、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.Service1Installer, 
    this.Service2Installer}); 

} 
関連する問題