The Power Management Exit routine was instructing the thread to
terminate but was not waiting for the conclusion of the operation
before returning control to the caller. This allows the service
to pass control to the Service Manager before cleanup was properly
completed.
case WAIT_OBJECT_0:
// termination signaled
RevertToSelf();
- Sleep(500);
ExitThread(0);
break;
if (gThreadHandle)
{
SetEvent(gThreadInfo.hEventTerminate);
+ WaitForSingleObject(gThreadHandle, INFINITE);
CloseHandle(gThreadHandle);
}
}