【发布时间】:2011-03-02 20:06:14
【问题描述】:
我有一个 C# 程序,它充当我创建的 Windows 服务的 GUI。可以根据 GUI 中的按钮按下来停止或启动服务...启动按钮按下事件将调用以下函数。在我的普通电脑上,这段代码运行良好。但是,当我将此 GUI 应用程序放在我的服务器上时,它不会启动或停止服务。是否有我遗漏的东西,或者服务器服务与常规 PC 服务的流程不同。我正在使用 Windows Server 2008 R2 和 Vista Business...提前致谢。
public static bool StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
if (service.Status == ServiceControllerStatus.Running)
return true;
else
return false;
}
catch
{
// ...
return false;
}
}
【问题讨论】:
标签: c# windows windows-services windows-server-2008