Prev: Chart
Next: Thread.join
From: Peter Larsen [CPH] on
Hi,

What is the normal way to stop a servie from within the servie itself ??

BR
Peter


From: Mr. Arnold on
Peter Larsen [CPH] wrote:
> Hi,
>
> What is the normal way to stop a servie from within the servie itself ??
>

<http://www.google.com/#hl=en&source=hp&q=Windows+service+shutdown+programically&btnG=Google+Search&aq=f&aqi=&aql=&oq=Windows+service+shutdown+programically&gs_rfai=C6ZxLawwaTJ2TB5G2zQTCoKWfAwAAAKoEBU_QI6Z8&fp=652ba8543c4f91ab>
From: Arne Vajhøj on
On 17-06-2010 05:06, Peter Larsen [CPH] wrote:
> What is the normal way to stop a servie from within the servie itself ??

The service extends ServiceBase and that has a Stop method.

I have never tried it, but I would expect it to
stop the service.

Arne

From: Peter Larsen [CPH] on
Thanks for your comments.

I know about ServiceBase.Stop(), but what is best practice ?

What is if i want to stop with error (Environment.Exit() or throw an
exception) ?
Both ways, the service stops immediately without any cleanups (no go i would
say).

/Peter


From: Jeff Johnson on
"Peter Larsen [CPH]" <PeterLarsen(a)community.nospam> wrote in message
news:Odw7fRtDLHA.352(a)TK2MSFTNGP02.phx.gbl...

> Thanks for your comments.
>
> I know about ServiceBase.Stop(), but what is best practice ?
>
> What is if i want to stop with error (Environment.Exit() or throw an
> exception) ?
> Both ways, the service stops immediately without any cleanups (no go i
> would say).

So write a cleanup method whose final line calls Stop(). Stopping with an
error code is a bad idea in my opinion, like some throwback to DOS. I
recommend writing an error to the event log instead of an returning error
code.


 |  Next  |  Last
Pages: 1 2
Prev: Chart
Next: Thread.join