Re: Windows service shutdown
- From: "tshad" <tfs@xxxxxxxxxxxxxx>
- Date: Fri, 10 Oct 2008 15:53:59 -0700
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.uitk55qf8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Fri, 10 Oct 2008 08:54:55 -0700, tshad <tfs@xxxxxxxxxxxxxx> wrote:Because in this case it is a FileWatcher that is running through files and
[...]
What I don't know is what is the duration of time that a service has to
shutdown before it gets that message, or is there a setting somewhere
where
you can set it?
Rather than worrying about that specific duration, you should just fix the
service so that it doesn't become unresponsive while it's sleeping (why
you feel it necessary for it to sleep "for about 10-20 minutes" is hard to
understand too, but for the moment let's assume that's actually necessary
even though it doesn't seem quite right).
processing them and depends on SQL Server. If Sql Server goes down
(maintenance, reboots, crashes etc), I want the Service to go to sleep for a
specified amount of time and then try again. If it is still down it will do
that again - each time sending a message that it is still getting a timeout.
I don't want it to be checking again right after it got the error over and
over again sending messages every 20 seconds.
I figure 10 minutes or so is a good duration.
From your description (it's impossible to know for sure without a
concise-but-complete code sample) in the thread that would normally
process messages for the service, you are calling something like
Thread.Sleep() with some long value. That, of course, causes the server
to fail to respond to _any_ message.
Which is why I changed the code to go to sleep for a minute, wake up and
check if the stop button was pressed. If not, it goes to sleep for another
minute until the maximum amount of minutes has gone by. If the stop button
was pressed, it exits the thread (after releasing the Mutex I am using).
Thanks,
Tom
Instead of blocking that thread, you should simply be setting some state
variable that indicates that the service is in its "sleeping" state. Any
requests that come in while that flag is set can be ignored, rejected,
etc. as appropriate but you would still respond appropriately to shutdown
requests. At the same time that you set the flag, start a timer that will
clear the flag when the timer period has elapsed.
In that way, you will leave your service responsive, and it can even
shutdown properly in the middle of this "sleeping" state, but it will
still not respond to actions that you want to be suspended during the
"sleeping" state.
Pete
.
- Follow-Ups:
- Re: Windows service shutdown
- From: Peter Duniho
- Re: Windows service shutdown
- References:
- Windows service shutdown
- From: tshad
- Re: Windows service shutdown
- From: Peter Duniho
- Windows service shutdown
- Prev by Date: RE: Problem downloading a file with HTTP - partial fix
- Next by Date: Re: Windows service shutdown
- Previous by thread: Re: Windows service shutdown
- Next by thread: Re: Windows service shutdown
- Index(es):