Dealing w/ Lengthy Processing in Service Control Handler

Last reviewed: September 25, 1995
Article ID: Q120557
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1, 3.5, and 3.51
    

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
KBCategory: kbprg
KBSubcategory: BseService


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 25, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.