473,385 Members | 1,707 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.

Delay Windows Service Shutdown...

Ash
Hi coders,
I have a service that does alot of data copying to the database and when the
service is stopped or the machine is shutting down it commits the data (in
addition to other things) and makes sure it exists gracefully (this could
take upto 5-6 mins).

I tried increasing
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\WaitToKillServiceTimeout
to 5 mins (300000) on a test service that sleeps for 4 mins when
OnStop/Shutdown is called but that didnt work, I also tried using
RequestAdditionalTime(290000) but again that didnt work.
In all my test cases the SCM returns after 2 mins with Error 1053 (timeout)
and marks the service as stopping but never waits the time specified in
RequestAdditionalTime or the WaitToKillServiceTimeout.
ServiceBase.CanShutdown and ServiceBase.CanStop are both set to true

In the case of the OnStop the SCM doesnt kill the EXE and service completes
its task but if it is a Shutdown the exe gets killed before the time elapses.

Am i missing somthing, are these settings being overwritten somewhere else?
Note that
Thanks alot.
-Ash
Jul 18 '06 #1
6 9470
Ash,

If I am not mistaken, Windows ultimately will disregard requests for
more time after 30 seconds (I could be wrong on the time).

Frankly, it's not a good idea to keep the machine running for another
5-6 minutes if a user requested a shutdown. Is there any way that you can
write the data while the service is running, instead of dumping it all in
the end?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ash" <As*@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
Hi coders,
I have a service that does alot of data copying to the database and when
the
service is stopped or the machine is shutting down it commits the data (in
addition to other things) and makes sure it exists gracefully (this could
take upto 5-6 mins).

I tried increasing
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\WaitToKillServiceTimeout
to 5 mins (300000) on a test service that sleeps for 4 mins when
OnStop/Shutdown is called but that didnt work, I also tried using
RequestAdditionalTime(290000) but again that didnt work.
In all my test cases the SCM returns after 2 mins with Error 1053
(timeout)
and marks the service as stopping but never waits the time specified in
RequestAdditionalTime or the WaitToKillServiceTimeout.
ServiceBase.CanShutdown and ServiceBase.CanStop are both set to true

In the case of the OnStop the SCM doesnt kill the EXE and service
completes
its task but if it is a Shutdown the exe gets killed before the time
elapses.

Am i missing somthing, are these settings being overwritten somewhere
else?
Note that
Thanks alot.
-Ash

Jul 18 '06 #2
Ash
Nicholas,
Thank you for the quick reply. Unfortunatly this is not an option because
the process is not writing the data directly. Instead my service periodicly
calls an external tool that acts like a bulk copier (kinda like bcp) that
copies the data to the db and commits it in two phases;
Phase #1: Copying data to the db
Phase #2: Applying a sequence of DML on the copied data

If a machine shutdown or Service Stop is requested right after the service
invokes this external utility then the service cannot abort before the that
external tool returns (which could be the 6 mins that i was talking about).
This might cause data corruption if the process gets aborted in the middle.
So in most cases the service will return immediatly if its not waiting for
that utility to finish but in the situations where the shutdown/stop is
requested in the middle i dont really care if the machine waits 6 mins. I
care more about the data.
I hope this makes sense.
Thanks for the help.
-Ash
Jul 18 '06 #3
Avoid delays in service stop. Move the "external utility" to a server, and
wrap some sort of interface around it (web service would be easy). Provide
interface methods to submit, check status, etc. Your Windows service should
just submit a "save" request to the web service (including the data), then
can immediately stop. If necessary, it can track the submitted request on
stop, and later check status on start.

"Ash" <As*@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Nicholas,
Thank you for the quick reply. Unfortunatly this is not an option because
the process is not writing the data directly. Instead my service
periodicly
calls an external tool that acts like a bulk copier (kinda like bcp) that
copies the data to the db and commits it in two phases;
Phase #1: Copying data to the db
Phase #2: Applying a sequence of DML on the copied data

If a machine shutdown or Service Stop is requested right after the service
invokes this external utility then the service cannot abort before the
that
external tool returns (which could be the 6 mins that i was talking
about).
This might cause data corruption if the process gets aborted in the
middle.
So in most cases the service will return immediatly if its not waiting for
that utility to finish but in the situations where the shutdown/stop is
requested in the middle i dont really care if the machine waits 6 mins. I
care more about the data.
I hope this makes sense.
Thanks for the help.
-Ash

Jul 18 '06 #4
Ash
Russell,
Thanks for the reply, but that could open an endless loop because the delay
will happen at some point or the other, what if that other server needs to be
rebooted (our servers are administered by a 3rd party that do not want to do
extra work when applying a patch or anything similar, they just want to hit
REBOOT and everything else should happen gracefully & automaticly).
Wouldn't that bring us to where we started ???
Thanks and I appreciate your thoughts...
Jul 18 '06 #5
On Tue, 18 Jul 2006 09:50:02 -0700, Ash wrote:
Russell,
Thanks for the reply, but that could open an endless loop because the delay
will happen at some point or the other, what if that other server needs to be
rebooted (our servers are administered by a 3rd party that do not want to do
extra work when applying a patch or anything similar, they just want to hit
REBOOT and everything else should happen gracefully & automaticly).
Wouldn't that bring us to where we started ???
Thanks and I appreciate your thoughts...
Production servers should only hav scheduled reboots - so don't initiate
your process before one of those times... If your 3rd party likes to reboot
your production servers on a whim, get another 3rd party! ;)

Cheers

- Andrew
Jul 27 '06 #6
Ash
I would agree with you if we were living in a perfect world. But
unfortunately you have to design your application to be fail safe with all
these situations.
It would be bad if you corrupt your database because the SA rebooted the
machine a little early or late.
I'm sure you'd agree.

"Andrew" wrote:
On Tue, 18 Jul 2006 09:50:02 -0700, Ash wrote:
Russell,
Thanks for the reply, but that could open an endless loop because the delay
will happen at some point or the other, what if that other server needs to be
rebooted (our servers are administered by a 3rd party that do not want to do
extra work when applying a patch or anything similar, they just want to hit
REBOOT and everything else should happen gracefully & automaticly).
Wouldn't that bring us to where we started ???
Thanks and I appreciate your thoughts...

Production servers should only hav scheduled reboots - so don't initiate
your process before one of those times... If your 3rd party likes to reboot
your production servers on a whim, get another 3rd party! ;)

Cheers

- Andrew
Jul 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bill Sonia | last post by:
I'm written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that once my send mail code is...
8
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
6
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only...
2
by: Mr Newbie | last post by:
I have an annoying teenager who wont go to bed because he is allways on his computer. I want to write a windows service which will shut down his computer at night and not allow this to be...
0
by: Stefan Krah | last post by:
Hello, I'm trying to run a Python script as a Windows service with a defined shutdown. The script (enigma-client.py) handles the communications with the server in a distributed computing effort...
0
by: Mathew Clark | last post by:
I'm trying to write a Windows Service that is capable of detecting when a shutdown is occurring, and cancelling it. I've managed to get this to work fine in a windows application, using...
4
by: Frank | last post by:
My program gets a WM_QUERYENDSESSION message and asks the user if it is OK to shutdown. While he's thinking about it, Windows displays a box saying the program is not responding, and if not...
3
by: IdleBrain | last post by:
Gurus, I am trying to delay Windows Shutdown/Restart to perfrom cleanup and I am using the following code: protected override void WndProc(ref Message ex)
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.