Don't bother with any of the timeout business if the state has

actually changed. Stops release builds incorrectly displaying
errors claiming that the service has failed to start/stop.
This commit is contained in:
Mike Crowe 2006-05-31 13:06:12 +00:00
parent c0e5416071
commit 58eb3d914b
1 changed files with 22 additions and 10 deletions

View File

@ -112,6 +112,7 @@ bool Service::StopAndWait()
bool Service::WaitPending(Status *status, DWORD existing_state) bool Service::WaitPending(Status *status, DWORD existing_state)
{ {
ATLTRACE(_T("Enter Service::WaitPending\n"));
if (GetStatus(status)) if (GetStatus(status))
{ {
DWORD dwStartTickCount = GetTickCount(); DWORD dwStartTickCount = GetTickCount();
@ -119,18 +120,26 @@ bool Service::WaitPending(Status *status, DWORD existing_state)
while (status->dwCurrentState == existing_state) while (status->dwCurrentState == existing_state)
{ {
ATLTRACE(_T("WaitPending\n")); ATLTRACE(_T("Service::WaitPending in loop\n"));
DWORD dwWaitTime = status->dwWaitHint / 10; DWORD dwWaitTime = status->dwWaitHint / 10;
if (dwWaitTime < 1000) if (dwWaitTime < 1000)
dwWaitTime = 1000; dwWaitTime = 1000;
else if (dwWaitTime > 10000) else if (dwWaitTime > 10000)
dwWaitTime = 10000; dwWaitTime = 10000;
ATLTRACE(_T("Sleeping\n"));
::Sleep(dwWaitTime); ::Sleep(dwWaitTime);
if (!GetStatus(status)) if (!GetStatus(status))
{
ATLTRACE(_T("Service::WaitPending - Failed to get status\n"));
return false; return false;
}
// If we haven't changed state yet then check to see that the
// service is actually making progress.
if (status->dwCurrentState == existing_state)
{
if (status->dwCheckPoint != dwOldCheckPoint) if (status->dwCheckPoint != dwOldCheckPoint)
{ {
// The service is making progress // The service is making progress
@ -139,11 +148,14 @@ bool Service::WaitPending(Status *status, DWORD existing_state)
} }
else if (GetTickCount() - dwStartTickCount > status->dwWaitHint) else if (GetTickCount() - dwStartTickCount > status->dwWaitHint)
{ {
ATLTRACE(_T("Service::WaitPending - No progress\n"));
/// Hmm. No progress /// Hmm. No progress
return false; return false;
} }
} }
} }
}
ATLTRACE(_T("Service::WaitPending success\n"));
return true; return true;
} }