Lee,
Which was the point of my second suggestion.
Leave the Service running, but have it go to a "sleep mode". By "sleep mode"
I mean if its waiting for an Async event, don't wait for the event. If it
has a second thread, kill the second thread. If its using a Timer, stop the
Timer. If its using Remoting, stop Remoting. If its using TCPListener, stop
listening. What ever it is using to decide it has work to do, simple don't
do that! Let all threads (explicit or ThreadPool) exit without a request to
come back for more. Yes the service itself would still be "running" however
it would not be doing anything, it would effectively be waiting for commands
from the SCM.
Because as you suggested, I'm really not sure what will happen if you used
End, nor do I see a "polite" way of tell the SCM, hey I had a problem please
terminate me.
This would effectively mean that a person would need to stop & start the
service again (or do a restart), which can be a good thing, as the person
could diagnose any problems!
Or in the simplest sense: set a global variable to true, in all of your
routines if the global variable is true, exit routine!
Hope this helps
Jay
"Lee Schipper" <la*@nospamlabapps.com> wrote in message
news:kW****************@twister.socal.rr.com...
Herfried wrote: <snip>I wouldn't use 'End' at all.<snip>
I agree wholeheartedly with the sentiment, just couldn't find any good
alternative.
Jay wrote: <snip>I would not expect a Windows Service to want to commit
"suicide", in any circumstances! I would expect it to have good error
handling and log all errors, and maybe put itself into a stop like
state.<snip>
I trap and *try* to recover from any error, but wanted to leave room for
the possibility that something might happen that I could not recover from.
Basically I am trying to resolve the "when all else fails" scenario. I
had envisioned that I would have the service removed from memory and have it
appear in the Service Control Manager as stopped.
I have had services spew out thousands of redundant errors into my log.
That irritates the heck out of me and I didn't want my service to be one
of "those" services -- mine should know when it was best to just throw in the
towel.
I did think about creating a ServiceController and sending a stop to
myself, but not knowing the exact mechanism of the stop request I got worried
about possible complications, and figured it was not worth the risk or trouble.
After all this would be code that *should* never get run anyway.
Besides, what if ServiceController.Stop() throws an exception...then what?
<GRIN>
Thanks for your feedback.
Lee