![](/img/trans.png)
[英]RegisterHotkey only working in WIndows 7, not in XP, server 2003
[英]How can I delay my created service in Windows Server 2003 & Windows XP?
我很多天前做了一个服务(WinServiceProject),我希望它可以自动启动,但是有延迟的时间...我找到了解决方案,但不能帮到我: http : //support.microsoft.com/kb/193888/en -我们
我在HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ WinServiceProject上修改了regedit,但这不起作用。
我添加了多字符串值(DependOnService)并在此之前设置了许多服务。
我需要随着时间的解决方案,设置很多时间,然后再执行该服务。 如果需要在我的服务中添加代码,我会这样做。
谢谢。
我用这个代码解决了问题!!
公共静态无效RestartService(字符串serviceName,int timeoutMilliseconds)
{
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
{
// ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.