Whats the trade off b开发者_如何学Goetween using waitHandle and using threadPool's Property Thread.CurrentThread.IsThreadPoolThread ? Considering the fact my methods in threadpool are brief ? does it makes sense to use waitHandle to consider it not waiting ?
ThreadPool.QueueUserWorkItem(delegate
{
DoWork(Top, Bottom);
});
if (Thread.CurrentThread.IsThreadPoolThread == false
&& SomeotherCondition == false )
{
// Uses the Dowork
}
Redefining the questions: when should one use waitHandle and when IsThreadPoolThread?
Use a WaitHandle
when you want a thread to wait for some operation to complete. Use IsThreadPoolThread
when you want to know if a thread is a thread pool thread. To put it another way, use a rocket if you want to go into space, and make a salad if you want to eat vegetables.
精彩评论