我有以下问题。
我有两个要在同一应用程序 (WPF) 中启动的 Windows 服务应用程序,它们都已安装。但是当我必须“启动”它们时 (ServiceController.Start()),只有首先启动的服务保持打开状态,另一个返回消息:
Error 1053: The service did not respond to the start or control request in a timely fashion
这是我启动它们的代码:
//*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 社区的第一个问题,英语不是我的母语。 如果我犯了任何错误,我深表歉意。
最佳答案
问题已解决!
我只需要从 Debug 更改为 Release 并安装 Release .exe,现在这两个服务都可以正常运行。
关于c# - 在同一应用程序中启动两个 Windows 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38997088/