Task.ContinueWith使用什么SynchronizationContext? [英] What SynchronizationContext does Task.ContinueWith use?

查看:79
本文介绍了Task.ContinueWith使用什么SynchronizationContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Task.ContinueWith 的某些重载不采用SynchronizationContext。他们使用什么SynchronizationContext来计划新任务?

Some overloads of Task.ContinueWith do not take a SynchronizationContext. What SynchronizationContext do they use to schedule the new task?

推荐答案


Task.ContinueWith的一些重载

Some overloads of Task.ContinueWith do not take a SynchronizationContext.

实际上,它们都不使用 SynchronizationContext ,但是有些会使用 TaskScheduler

Actually, none of them take a SynchronizationContext, but some take a TaskScheduler.


他们使用什么SynchronizationContext来安排新的

What SynchronizationContext do they use to schedule the new task?

没有!默认情况下,继续由当前调度程序( 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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