Running is pooling loop is not right either. A ~better way is to have
thread block on an empty work queue. A clean way to stop is to enqueue
multiple "Close" objects to the queue, so each thread will see a
Close/Shutdown object and exit nicely. Another way is to flip your flag (in
a sync context - lock) then Interrupt each thread. Each thread will get the
Interrupt exception which they will catch and drop out of their loops
respectively. Don't use Abort.
--
William Stacey [MVP]
[quoted text, click to view] "Techno_Dex" <nospamchurst@osi-corp.com> wrote in message
news:O8$nVarpGHA.4032@TK2MSFTNGP03.phx.gbl...
| Why waste the overhead time of initializing a Thread and tearing it down
| after every execution? More time and resources would be wasted getting
| everything configured and up and running for the Thread each time. So
back
| to my original question?
|
[quoted text, click to view] | "Kevin Spencer" <uce@ftc.gov> wrote in message
| news:eebMuRqpGHA.4760@TK2MSFTNGP05.phx.gbl...
| > Why not use a timer and run the threads when you need to, rather than
| > putting them to sleep? That way, all you have to do is stop the timer.
| >
| > --
| > HTH,
| >
| > Kevin Spencer
| > Microsoft MVP
| > Professional Chicken Salad Alchemist
| >
| > What You Seek Is What You Get.
| >
| >
[quoted text, click to view] | > "Techno_Dex" <nospamchurst@osi-corp.com> wrote in message
| > news:eQ2sTRopGHA.1600@TK2MSFTNGP04.phx.gbl...
| >> What is the proper way to terminate a Thread in a Windows Service? I
| >> have a windows service which starts up three threads which run in a
while
| >> loop as long as a boolean flag is set to true. These threads each
sleep
| >> for X ammount of time then start processing again. Since this is a
| >> service it's basically running in an infinite loop. When the user goes
| >> to stop the service, I have been calling the Thread.Abort() method,
which
| >> throws a ThreadAbortedException. I've also tried using the
| >> Thread.Interupt() method to wake any sleeping threads, but that too
| >> throws a ThreadInteruptedException. What is the proper way to kill
these
| >> threads in the 30 second timeframe that the windows service framework
| >> gives a service to respond back? If catching these Exceptions are the
| >> correct way to stop the service, what is the correct way to know if the
| >> service actually dies on it's own for some reaon (i.e. god forbid
| >> locking)?
| >>
| >
| >
|
|