Windows Service Best Practices

  • Thread starter Thread starter Shawn Meyer
  • Start date Start date
S

Shawn Meyer

Hello,

I have a windows service. When the onstart fires, my app creates two
threads. The first is a processing thread and the second is a watcher that
makes sure the everything is ok with the first thread. When a problem is
detected the second (watcher) thread stops the processing thread and then
throws an exception. This exception does not stop the service like I would
think.

My question is, what is the best way for the watcher thread to shut the
service down.

Thanks,
Shawn
 
Shawn,

I assume to throw an event in the worker thread that when it is catched by
the main thread, stops the whole application (including the workerthread by
telling that that is a background thread).

Just my thought,

Cor
 
Hi Shawn,

First, you don't want an exception to shut the application down. What you
want is for an exception *handler* to shut the application down. The
difference is that the handler can shut it down gracefully. Therefore, you
can use an event in either thread that is raised when an exception occurs,
and subscribe to the event in the other thread.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Back
Top