2016-08-17 12 views
2

私は次の問題があります。同じアプリケーションで2つのWindowsサービスを開始する

私は同じアプリケーション(WPF)で起動する2つのWindowsサービスアプリケーションを持っていますが、どちらも既にインストールされています。サービス開始時にServiceController.Start()を開始する必要がある場合、最初に開始するサービスのみがオンになり、他のサービスはメッセージを返します。

エラー1053:サービスは開始に応答しませんでしたまたは適時に制御 要求

これは、それらを開始するために私のコードです:

//*TS_TimeOut timespan has 1 hour 
    private void InitServiceOne() 
    { 
     ServiceController SControllerServiceOne = new ServiceController("ServiceOne", Environment.MachineName); 

     SControllerServiceOne.Start(); 
     SControllerServiceOne.WaitForStatus(ServiceControllerStatus.Running, TS_TimeOut); 
    } 

    private void InitServiceTwo() 
    { 

     ServiceController SControllerServiceTwo = new ServiceController("ServiceTwo", Environment.MachineName); 

     SControllerServiceTwo.Start(); 
     SControllerServiceTwo.WaitForStatus(ServiceControllerStatus.Running, TS_TimeOut); 
    } 

これは私がそれらをインストールするために使用したコードです

private void InstallServiceOne(string strServiceOnePath) 
    { 
     ServiceProcessInstaller ProcessServiceServiceOne = new ServiceProcessInstaller(); 

     ServiceInstaller ServiceInstallerOne = new ServiceInstaller(); 
     InstallContext Context = new System.Configuration.Install.InstallContext(); 
     String path = String.Format("/assemblypath={0}", strServiceOnePath)); 
     String[] cmdline = { path }; 

     Context = new System.Configuration.Install.InstallContext("", cmdline); 
     ServiceInstallerOne.Context = Context; 
     ServiceInstallerOne.DisplayName = "ServiceOne"; 
     ServiceInstallerOne.Description = "ServiceOne"; 
     ServiceInstallerOne.ServiceName = "ServiceOne"; 
     ServiceInstallerOne.StartType = ServiceStartMode.Automatic; 
     ServiceInstallerOne.Parent = ProcessServiceServiceOne; 

     System.Collections.Specialized.ListDictionary stateServiceOne = new System.Collections.Specialized.ListDictionary(); 
     ServiceInstallerObjIntegracao.Install(stateServiceOne); 
    } 

    private void InstallServiceTwo(string strServiceTwoPath) 
    { 

     ServiceProcessInstaller ProcessServiceServiceTwo new ServiceProcessInstaller(); 

     ServiceInstaller ServiceInstallerTwo = new ServiceInstaller(); 
     InstallContext Context = new System.Configuration.Install.InstallContext(); 
     String path = String.Format("/assemblypath={0}", strServiceTwoPath); 
     String[] cmdline = { path }; 

     Context = new System.Configuration.Install.InstallContext("", cmdline); 
     ServiceInstallerTwo.Context = Context; 
     ServiceInstallerTwo.DisplayName = "ServiceTwo"; 
     ServiceInstallerTwo.Description = "ServiceTwo"; 
     ServiceInstallerTwo.ServiceName = "ServiceTwo"; 
     ServiceInstallerTwo.StartType = ServiceStartMode.Automatic; 
     ServiceInstallerTwo.Parent = ProcessServiceServiceTwo; 

     System.Collections.Specialized.ListDictionary stateServiceTwo = new System.Collections.Specialized.ListDictionary(); 
     ServiceInstallerObjBRMonitoring.Install(stateServiceTwo); 

    } 

これは私の母国語ではなく、stackoverflowコミュニティの最初の質問です。 私は間違いを犯した場合、謝罪します。

+0

イベントビューアで例外の詳細を調べましたか? –

+0

私が確認したいのは、 'InitServiceOne'を実行する前に' InitServiceTwo'を実行すると、 "two"サービスと "one"サービスがタイムアウトしますか? –

+0

はい、InitServiceOneの前にInitServiceTwoを実行すると、ServiceTwoが正常に動作します。 –

答えて

1

問題は解決されました。

デバッグからリリースに変更し、リリース.exeをインストールするだけで、両方のサービスが動作していて問題なく動作するようになりました。

関連する問題