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를 수정하지만 작동하지 않습니다.
다중 문자열 값 (dependongervice)을 추가하고 이전에 많은 서비스를 설정 ...이 작동하지만 내가 원하는 것을 좋아하지는 않습니다.
시간이 필요하고,이 시간이 지나면 시간이 걸리고 서비스를 실행하는 솔루션.내 서비스에 코드를 추가 해야하는 경우 나는 그것을 할 것입니다.
감사합니다.
해결책
이 코드로 문제를 해결합니다 !!
공용 정적 void restartservice (String ServiceName, int timeoutmillieConds)
{
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