TaskCreationOptions.LongRunning 选项和 ThreadPool [英] TaskCreationOptions.LongRunning option and ThreadPool

查看:37
本文介绍了TaskCreationOptions.LongRunning 选项和 ThreadPool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TPL 使用任务调度器来协调任务.根据官方文档,默认任务调度器使用线程池,但如果<代码>TaskCreationOptions.LongRunning 选项,然后它将为该任务(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).

问题:截至目前,Visual Studio 2010 的 MSDN 文档尚未准备好,当前在线 MSDN 尚未最终确定;有谁知道(A)是对还是错?

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

推荐答案

是的,LongRunning 强制在池外创建新线程.下面是来自最新框架版本的一些伪反汇编代码:

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)
...

从丑陋的 C# 转换为伪代码.

这篇关于TaskCreationOptions.LongRunning 选项和 ThreadPool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆