问题描述
的某些重载不采用SynchronizationContext。他们使用什么SynchronizationContext来计划新任务?
Some overloads of Task.ContinueWith do not take a SynchronizationContext. What SynchronizationContext do they use to schedule the new task?
推荐答案
实际上,它们都不使用 SynchronizationContext
,但是有些会使用 TaskScheduler
。
Actually, none of them take a SynchronizationContext
, but some take a TaskScheduler
.
没有!默认情况下,继续由当前调度程序( TaskScheduler.Current
)调度,当未从 Task
,是 TaskScheduler.Default
。因此,继续在线程池中的线程上运行。 ThreadPool
线程没有关联的同步上下文(除非您明确设置了同步上下文)。
None! By default, the continuation is scheduled by the current scheduler (TaskScheduler.Current
), which, when not called from a Task
, is TaskScheduler.Default
. So the continuation is run on a thread from the thread pool. ThreadPool
threads don't have an associated synchronization context (unless you explicitly set one).
这篇关于Task.ContinueWith使用什么SynchronizationContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!