C# Is it possible to interrupt a specific thread inside a ThreadPool?
Posted
by Lirik
on Stack Overflow
See other posts from Stack Overflow
or by Lirik
Published on 2010-03-12T05:03:11Z
Indexed on
2010/03/12
5:07 UTC
Read the original article
Hit count: 325
Suppose that I've queued a work item in a ThreadPool
, but the work item blocks if there is no data to process (reading from a BlockingQueue
). If the queue is empty and there will be no more work going into the queue, then I must call the Thread.Interrupt
method if I want to interrupt the blocking task, but how does one do the same thing with a ThreadPool
?
The code might look like this:
void Run()
{
try
{
while(true)
{
blockingQueue.Dequeue();
doSomething();
}
}
finally
{
countDownLatch.Signal();
}
}
I'm aware that the best thing to do in this situation is use a regular Thread
, but I'm wondering if there is a ThreadPool
equivalent way to interrupt a work item.
© Stack Overflow or respective owner