473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2720
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
1
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service...
9
by: Ron | last post by:
my application is throwing an exception error when closing if I run a procedure in the app. I can't even trap the error with try/catch ex As Exception. Is there a way to completely shut down the...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
10
by: Jim Underwood | last post by:
I am having a problem with my web page timng out while retrieving a long runnign report (90-120 seconds. I have tried modifying several settings in various places and cannot get it to run for more...
12
by: Jan | last post by:
Hi: I've got the Error 3197 problem ("The Microsoft Jet database engine stopped the process because you and another user are attempting to change the same data at the same time.") in a client...
5
by: Josh | last post by:
I have application1 that connects to webService1. I have a second application that references the same webservice (webService1). I need to pass an instance of a class returned from webService1...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.