Thread management in a Windows service

  • Thread starter Thread starter Gregory Gadow
  • Start date Start date
G

Gregory Gadow

I have a service written in VB.Net 2.0 that watches a folder for text
files and, when a text file is placed in the folder, moves it elsewhere
and processes it. I would like to optimize the service by putting each
document on its own worker thread.

My main question is: what would happen if a service shut-down command is
issued and there are pending threads? I am hoping that the service will
wait until all of the worker threads have terminated before shutting
down, but I fear it won't be that easy. Any suggestions -- or better,
code examples available on the web -- would be much appreciated.
 
I don't have a code example handy, but probably the easiest way to do work in
the background is using the new BackgroundWorker component. I believe that
when a service gets a shutdown notification, it will end up calling your
service code to do the shutdown. In here, you could either wait for the
background workers to complete, or send a cancel to them to make them
terminate.
 

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

Back
Top