Ionline
January 10th, 2004, 04:45 AM
Hi,
I am planning to use StartService or ControlService api for starting or stopping a service using either . To break out of start/stop pending servive, I have observed that we can use either two ways as follows:
// Wait for the service to stop
while ( ss.dwCurrentState != SERVICE_STOPPED ) {
Sleep( ss.dwWaitHint );
if ( !QueryServiceStatus( hDepService, &ss ) )
return GetLastError();
if ( ss.dwCurrentState == SERVICE_STOPPED )
break;
if ( GetTickCount() - dwStartTime > dwTimeout )
return ERROR_TIMEOUT;
}
where dwStartTime = GetTickCount() during start of program and
dwTimeout will be a signature for the function.
OR
DWORD dwChkP ;
while ( ss.dwCurrentState != SERVICE_STOPPED ) {
dwChkP = ssStatus.dwCheckPoint;
Sleep( ss.dwWaitHint );
if ( !QueryServiceStatus( hDepService, &ss ) )
return GetLastError();
if ( ss.dwCurrentState == SERVICE_STOPPED )
break;
if(ssStatus.dwCheckPoint < dwChkP)
break;
}
if (SERVICE_RUNNING != ssStatus.dwCurrentState)
return ERROR_TIMEOUT;
// Here I dont have to worry about dwTimeout
Which is the better approach from the above code snippets??
I am planning to use StartService or ControlService api for starting or stopping a service using either . To break out of start/stop pending servive, I have observed that we can use either two ways as follows:
// Wait for the service to stop
while ( ss.dwCurrentState != SERVICE_STOPPED ) {
Sleep( ss.dwWaitHint );
if ( !QueryServiceStatus( hDepService, &ss ) )
return GetLastError();
if ( ss.dwCurrentState == SERVICE_STOPPED )
break;
if ( GetTickCount() - dwStartTime > dwTimeout )
return ERROR_TIMEOUT;
}
where dwStartTime = GetTickCount() during start of program and
dwTimeout will be a signature for the function.
OR
DWORD dwChkP ;
while ( ss.dwCurrentState != SERVICE_STOPPED ) {
dwChkP = ssStatus.dwCheckPoint;
Sleep( ss.dwWaitHint );
if ( !QueryServiceStatus( hDepService, &ss ) )
return GetLastError();
if ( ss.dwCurrentState == SERVICE_STOPPED )
break;
if(ssStatus.dwCheckPoint < dwChkP)
break;
}
if (SERVICE_RUNNING != ssStatus.dwCurrentState)
return ERROR_TIMEOUT;
// Here I dont have to worry about dwTimeout
Which is the better approach from the above code snippets??