如何在Windows Server 2003和Windows XP中延迟我创建的服务?
-
21-12-2019 - |
题
我多天前发了一份服务(WinserviceProject),我希望这开始自动但是延迟时间......我找到了一个解决方案,但这不能帮助我: http://support.microsoft.com/kb/193888/en-us
我在hkey_local_machine \ system \ currentcontrolset \ services \ winserviceproject上修改regedit,但这不起作用。
我添加多字符串值(DepiteNservice)并在之前设置许多服务......这有效,但不喜欢我想要的。
我需要它的解决方案,设置多次并在此后执行服务。如果我需要为我的服务添加代码,我会这样做。
谢谢。
解决方案
我解决了这个代码的问题!!
公共静态void restartservice(String servicename,int timoutmilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
int millisec1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
// count the rest of the timeout
//int millisec2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - millisec1);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
}
. 不隶属于 StackOverflow