Windows Service Best Practices

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
 
C

Cor Ligthert [MVP]

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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top