2016-08-17 111 views
2

我遇到以下問題。在同一應用程序中啓動兩個Windows服務

我有兩個Windows服務應用程序啓動在同一個應用程序(WPF),都已經安裝。但是,當我有「開始」他們(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'服務「兩個」工作和服務「一」超時? –

+0

是的,如果我在InitServiceOne之前運行InitServiceTwo,ServiceTwo可以正常工作。 –

回答

1

問題已解決!

我只需將Debug從Debug更改爲Release並安裝Release .exe,現在兩個服務都可以正常運行並且沒有任何問題。

相關問題