469,935 Members | 2,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

Error when my Win32 Service takes longer than 30 seconds to shut down.

All:

I have a Win32 service that takes about 30 seconds to shutdown (give or take
a few seconds). I shut the service down via the 'Services' console on
Windows Server 2003. When the service shuts down in under 30 seconds,
everything is fine. However if the service takes over 30 seconds to shut
down, I get the following error in the System Event Log:

"Timeout (30000 milliseconds) waiting for a transaction response from the
XYZ service."

I get this error even though I frequently increment the 'dwCheckPoint' value
via a call to SetServiceStatus() during the shutdown sequence.

From the MSDN docs on the SetServiceStatus() API, bumping this value should
inform the SCM that my service needs a little more time to shutdown.

Any ideas?

Thanks,
Bill
Jan 16 '08 #1
2 2501
Hi Bill,

Windows service has very restricted rule for the control code operation.
Basically, the HandlerEx function(this function is encapsulated in .Net
Windows Service to call your OnStop, OnShutdown handlers) must return
within 30 seconds, or the SCM will think that the service has stopped
responding.

SetServiceStatus with dwCheckPoint and dwWaitHint members is merely a hint
to the SCM how long it taks, it can not be used to delay the shutdown of
service or system. Jeffrey Richter's book <Programming Server-Side
Applications for Microsoft Windows 2000"Control Codes and Status
Reporting" section in chapter2 talks about these rules in details.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 16 '08 #2
Jeffrey:

Thanks for the good information. Based on your reply, I found the following
additional information for theService Control Handler function under
http://msdn2.microsoft.com/en-us/library/ms685149.aspx

"The control handler must return within 30 seconds, or the SCM returns an
error. If a service must do lengthy processing when the service is executing
the control handler, it should create a secondary thread to perform the
lengthy processing, and then return from the control handler. This prevents
the service from tying up the control dispatcher. For example, when handling
the stop request for a service that takes a long time, create another thread
to handle the stop process. The control handler should simply call
SetServiceStatus with the SERVICE_STOP_PENDING message and return.."

Once I did this, everything worked fine. I returned from the handler
quickly (just after calling SetServiceStatus with a status of
SERVICE_STOP_PENDING). On a separate thread, I proceeded with my lenghty
shutdown logic, bumping the dwCheckPoint value at periodic intervals to let
the SCM know the service wasn't hung. When my shutdown logic had completed
(about 60 seconds later), I again called SetServiceStatus with a status of
SERVICE_STOPPED, and the 'Service Console' then correctly showed the service
as stopped. Both the SCM and my service we're happy (i.e. no errors
reported from either)..

Thanks also for the Richter book reference. He is an outstanding author.

Bill

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:Wx**************@TK2MSFTNGHUB02.phx.gbl...
Hi Bill,

Windows service has very restricted rule for the control code operation.
Basically, the HandlerEx function(this function is encapsulated in .Net
Windows Service to call your OnStop, OnShutdown handlers) must return
within 30 seconds, or the SCM will think that the service has stopped
responding.

SetServiceStatus with dwCheckPoint and dwWaitHint members is merely a hint
to the SCM how long it taks, it can not be used to delay the shutdown of
service or system. Jeffrey Richter's book <Programming Server-Side
Applications for Microsoft Windows 2000"Control Codes and Status
Reporting" section in chapter2 talks about these rules in details.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 16 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
10 posts views Thread by Jim Underwood | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.