Microsoft KB Archive/120557

{|
 * width="100%"|

INFO: Dealing w/ Lengthy Processing in Service Control Handler

 * }

Q120557

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * the operating system: Microsoft Windows NT, versions 3.1, 3.5, 3.51
 * the operating system: Microsoft Windows 2000

-

SUMMARY
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 query words: 3.10 3.50

Keywords : kbAPI kbKernBase kbOSWin2000 kbService kbDSupport kbGrpDSKernBase

Issue type : kbinfo

Technology : kbAudDeveloper kbWin32sSearch kbWin32API