Dealing w/ Lengthy Processing in Service Control HandlerLast reviewed: September 25, 1995Article ID: Q120557 |
The information in this article applies to:
The service control handler function must return within 30 seconds. If it does not, the Service Control Manager will return the following error: "Error 2186 - The service is not responding to the control function". If a service needs to do lengthy processing when the service is in the service control handler, it should create a secondary thread to perform the lengthy processing and then return. This prevents the service from tying up the service control handler thread. If you are processing a SERVICE_CONTROL_STOP, you may wish to register a status of SERVICE_STOP_PENDING. The dwWaitHint should be at least 30 seconds. You can make the control panel applet wait for a long time if you send multiple SERVICE_STOP_PENDING states which update the dwCheckPoint and use a long dwWaitHint. The system shutting down is another event that limits the service control handler. The dwCtrlCode parameter for the service control handler returns SERVICE_CONTROL_SHUTDOWN. A service then has approximately 20 seconds to perform cleanup tasks. If the tasks are not done, the system shuts down regardless if the service shutdown is complete. If the user has selected "restart", all processes will halt quickly. If instead the system is left in the "shutdown" state, the service processes continue to run. If you need a longer time to shut down or earlier notification, consider using SetConsoleCtrlHandler() or SetProcessShutdownParameters() instead of using SERVICE_CONTROL_SHUTDOWN. This is the same mechanism that the Service Controller uses to get its notification.
|
Additional reference words: 3.10 3.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |