开发者

C# : whats the use of waitHandle when we can use the threadPool Property

开发者 https://www.devze.com 2023-02-26 02:59 出处:网络
Whats the trade off b开发者_如何学Goetween using waitHandle and using threadPool\'s PropertyThread.CurrentThread.IsThreadPoolThread ?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消