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:
parent
c0e5416071
commit
58eb3d914b
|
@ -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,31 +120,42 @@ 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))
|
||||||
return false;
|
|
||||||
|
|
||||||
if (status->dwCheckPoint != dwOldCheckPoint)
|
|
||||||
{
|
{
|
||||||
// The service is making progress
|
ATLTRACE(_T("Service::WaitPending - Failed to get status\n"));
|
||||||
dwStartTickCount = GetTickCount();
|
return false;
|
||||||
dwOldCheckPoint = status->dwCheckPoint;
|
|
||||||
}
|
}
|
||||||
else if (GetTickCount() - dwStartTickCount > status->dwWaitHint)
|
|
||||||
|
// If we haven't changed state yet then check to see that the
|
||||||
|
// service is actually making progress.
|
||||||
|
if (status->dwCurrentState == existing_state)
|
||||||
{
|
{
|
||||||
/// Hmm. No progress
|
if (status->dwCheckPoint != dwOldCheckPoint)
|
||||||
return false;
|
{
|
||||||
|
// The service is making progress
|
||||||
|
dwStartTickCount = GetTickCount();
|
||||||
|
dwOldCheckPoint = status->dwCheckPoint;
|
||||||
|
}
|
||||||
|
else if (GetTickCount() - dwStartTickCount > status->dwWaitHint)
|
||||||
|
{
|
||||||
|
ATLTRACE(_T("Service::WaitPending - No progress\n"));
|
||||||
|
/// Hmm. No progress
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ATLTRACE(_T("Service::WaitPending success\n"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue