|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Stopping my Windows Service ProgramaticallyHi all,
Can anybody tel me how to programatically kill my service when an exception occurs? Whenever something bad happens I'd like to shut it down. Also, is there a way to programatically restart my service at a set interval or when a particular condition is met within the application? Many thanks Simon On 6 Mar, 12:19, Simon Harvey <notha***@hotmail.com> wrote:
> Hi all, I do it this way:> > Can anybody tel me how to programatically kill my service when an > exception occurs? > > Whenever something bad happens I'd like to shut it down. > > Also, is there a way to programatically restart my service at a set > interval or when a particular condition is met within the application? > > Many thanks > > Simon ServiceController controller = new ServiceController(ConfigSettings.QueueSettings.QConfig.ServiceName); controller.Stop(); In this case I have the name of the service in my config as my installer is designed to allow multiple installs on the same computer. You can use the same controller instance to start services too. Hi,
"Simon Harvey" <notha***@hotmail.com> wrote in message Catching the exception is a better idea.news:e4DFkm%23XHHA.4560@TK2MSFTNGP03.phx.gbl... > Hi all, > > Can anybody tel me how to programatically kill my service when an > exception occurs? > Whenever something bad happens I'd like to shut it down. I think that treating the problem is a better solution> Also, is there a way to programatically restart my service at a set What kind of problems are you seeing that is that difficult to handle?> interval or when a particular condition is met within the application? On Tue, 06 Mar 2007 12:19:35 +0000, Simon Harvey wrote:
> Hi all, The ServiceContoller class is your friend. You can use it to start and stop> > Can anybody tel me how to programatically kill my service when an > exception occurs? > > Whenever something bad happens I'd like to shut it down. > > Also, is there a way to programatically restart my service at a set > interval or when a particular condition is met within the application? > > Many thanks > > Simon services based on set criteria. If you want to start it at timed intervals you could use a timer and within the appropriate event write the code that invokes the service controller
Show quote
On Mar 6, 11:08 pm, "Rad [Visual C# MVP]" <nos...@nospam.com> wrote: Be aware of using class System.Timers.Timer, and not the one in> On Tue, 06 Mar 2007 12:19:35 +0000, Simon Harvey wrote: > > Hi all, > > > Can anybody tel me how to programatically kill my service when an > > exception occurs? > > > Whenever something bad happens I'd like to shut it down. > > > Also, is there a way to programatically restart my service at a set > > interval or when a particular condition is met within the application? > > > Many thanks > > > Simon > > The ServiceContoller class is your friend. You can use it to start and stop > services based on set criteria. > > If you want to start it at timed intervals you could use a timer and within > the appropriate event write the code that invokes the service controller > -- > Bits.Byteshttp://bytes.thinkersroom.com System.Windows.Forms. They dond work the same way. Best regards Oscar Acosta |
|||||||||||||||||||||||