C# 在同一应用程序中启动两个windows服务

C# 在同一应用程序中启动两个windows服务,c#,.net,wpf,windows,service,C#,.net,Wpf,Windows,Service,我有以下问题 我有两个windows服务应用程序要在同一个应用程序(WPF)中启动,它们都已安装。但当我必须“启动”它们(ServiceController.Start())时,只有首先启动的服务保持打开状态,另一个返回消息: 错误1053:服务未响应启动或控制 及时请求 这是我启动它们的代码: //*TS_TimeOut timespan has 1 hour private void InitServiceOne() { ServiceController S

我有以下问题

我有两个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社区的第一个问题,英语不是我的母语。
如果我犯了任何错误,我深表歉意。

问题已经解决了


我刚从调试更改为发布并安装了Release.exe,现在这两个服务都在运行并且工作没有任何问题。

您是否在事件查看器中查看了任何异常详细信息?我想确认,如果您在运行
InitServiceOne
之前运行
InitServiceOne
服务“二”和服务“一”是否工作超时?是的,如果我在InitServiceOne之前运行initserviceotwo,serviceotwo工作正常。