在Task.Run默认TaskCreationOptions [英] Default TaskCreationOptions in Task.Run
问题描述
为什么对于 CreationOptions
的缺省值工作
使用 Task.Run <创建/ code>是
DenyChildAttach
,而不是无
?
Why the default value for CreationOptions
of a Task
created using Task.Run
is DenyChildAttach
rather than None
?
有它什么与做工作,新的异步
和等待
在C#5.0简单(由$ p $逃跑当前上下文我猜的)当前调度pventing吗?
Has it anything to do with making work with the new async
and await
in C# 5.0 simpler (by preventing you from escaping current scheduler of current context I guess)?
推荐答案
斯蒂芬Toub介绍了这口井<一个href=\"http://blogs.msdn.com/b/pfxteam/archive/2012/09/22/new-taskcreationoptions-and-taskcontinuationoptions-in-net-4-5.aspx\">in他的博客关于这个问题的。
Stephen Toub explains this well in his blog post on the subject.
家长和孩子的任务时使用有些常见的任务
S IN以并行的方式。请注意,当父工作
有一个孩子,父母的完成语义微妙地改变。
Parent and child tasks are somewhat common when using Task
s in a parallel fashion. Note that when a parent Task
has a child, the parent's completion semantics change subtly.
父/子任务,使用工作
S IN的异步
时尚时,几乎从来没有使用过。在异步
的世界里,你有一种逻辑父/子关系时,有一个异步
方法调用了另一个,但它不使用父/子任务实际实现
Parent/child tasks are almost never used when using Task
s in an async
fashion. In the async
world, you have a sort of "logical parent/child relationship" when one async
method calls another, but it is not actually implemented using parent/child tasks.
通常一个工作
拟用于异步
code未预计有其完成语义变化由子任务附加到它。因此,对于 Task.Run
新缺省值是 DenyChildAttach
,其中prevents的子任务尝试连接。
Usually a Task
intended for use in async
code is not expecting to have its completion semantics changed by a child task attaching to it. Thus, the new default for Task.Run
is DenyChildAttach
, which prevents any child tasks attempting to attach.
这篇关于在Task.Run默认TaskCreationOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!