[英]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.