Re: How should a Windows Service stop itself?
- From: "Dave" <none@xxxxxxxxxxx>
- Date: Tue, 8 Aug 2006 18:03:17 -0400
ServiceBase.Stop() isn't new in .NET 2.0.
I'm going to try Environment.Exit. That's what I was looking for, I just
didn't know what it was called.
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@xxxxxxxxxxxxx> wrote in
message news:uRMp9CvuGHA.1772@xxxxxxxxxxxxxxxxxxxxxxx
Rune,
| If you need to stop before OnStart is done, start an
| async. thread, ie. using a Timer, call ServiceController.Stop from
there.
If you need to stop before OnStart is done, simply call ServiceBase.Stop.
http://msdn2.microsoft.com/en-us/library/system.serviceprocess.servicebase.stop.aspx
If you are running .NET 1.x, I would first recommend upgrading, second
consider using the Environment.Exit hack, third consider using the async
thread hack
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Rune Huseby" <rhuseby2@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:Xns98189A468B484runehusebynewschello@xxxxxxxxxxxxxx
| "Dave" <none@xxxxxxxxxxx> wrote in
| news:ehu4X1duGHA.4752@xxxxxxxxxxxxxxxxxxxx:
|
| > I have written a multi-threaded Windows Service in .NET. During
| > startup of the service I need to check for some condition and stop the
| > service if the condition is not met. What is the best way to do that?
| > Due to time constraints I have to check the condition in a separate
| > thread created in the OnStart event so that the OnStart event can
| > complete within the 30 second window that Windows requires for service
| > start.
| >
| > I assume the only way for a service to stop itself is to use the
| > service controller class?
|
| That is correct, you use ServiceController.Stop. But you cannot do this
in
| the OnStart-event. If you need to stop before OnStart is done, start an
| async. thread, ie. using a Timer, call ServiceController.Stop from
there.
|
| --
| Rune Huseby
.
- Follow-Ups:
- Re: How should a Windows Service stop itself?
- From: Jay B. Harlow [MVP - Outlook]
- Re: How should a Windows Service stop itself?
- References:
- Re: How should a Windows Service stop itself?
- From: Rune Huseby
- Re: How should a Windows Service stop itself?
- From: Jay B. Harlow [MVP - Outlook]
- Re: How should a Windows Service stop itself?
- Prev by Date: Remote DB Access Security
- Next by Date: Re: How should a Windows Service stop itself?
- Previous by thread: Re: How should a Windows Service stop itself?
- Next by thread: Re: How should a Windows Service stop itself?
- Index(es):
Relevant Pages
|