开发者

TaskCreationOptions.LongRunning option and ThreadPool

开发者 https://www.devze.com 2023-01-04 18:07 出处:网络
TPL uses Task Schedulers to coordinate tasks. According to official document, default task scheduler uses Thread Pool, but if TaskCreationOptions.LongRunning option is presented then it will create a

TPL uses Task Schedulers to coordinate tasks. According to official document, default task scheduler uses Thread Pool, but if TaskCreationOptions.LongRunning option is presented then it will create a dedicated thread for that task (A).

Question: As of now MSDN documents for Visual Studio 2010 ar开发者_StackOverflowe not ready and current online MSDN is not finalized; does anyone knows if (A) is true or false?


Yes, LongRunning forces the creation of a new thread outside the pool. Here's some pseudo-disassembled code from the latest framework version:

...
if (task.Options HasFlag LongRunning) then
    create new Thread thread
    thread.Start(task)
...

Edit: converted from ugly C# to pseudocode.


Presumably you can check this by using "Thread.IsThreadPoolThread":

http://msdn.microsoft.com/en-us/library/system.threading.thread.isthreadpoolthread.aspx

0

精彩评论

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

关注公众号