Multi-threaded NT/W2K Service Question

R

Randy Geyer

I have an NT/W2K service that spawns 3 worker threads that each do different
things. For example, one monitors an email mailbox for incoming items and
puts them in a queue for processing by a 2nd thread. The 3rd thread polls a
database for updates and performs different processing. The actual
implementation is more complicated than this, but that's the basic
architecture.

My question is this: How do I gracefully shut down the service if one of
the worker threads encounters a fatal error? Example: if the mailbox is not
available, the service should gracefully stop (all threads) and log an
error. My current implementation will shutdown only the affected thread but
the others keep on going fat, dumb, and happy. This is not the desired
system behavior, but I'm not sure how to notify the main service thread of a
fatal error so it can shutdown the other threads and then gracefully stop
the service.

Is it as simple as calling the SCM and stopping the service from the failing
thread?

Any assistance is greatly appreciated! If this is not the proper group,
please redirect me.
 
L

Lee

You could create an event which can be raised when an error occurs. If you
have your 3 threads running subs in different classes, you could create a
public event in each class. By handling these events in your main thread,
you will be able to determine which thread caused the error, stop the
remaining threads and then shut down the service.

Hope this helps.

Lee.
 

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