Synchronization context for Task.Delay

徘徊边缘 提交于 2019-12-24 10:28:12

问题


I could find out that, Task.Run executes always on threads from .NET Framework threads pool (TaskScheduler.Default). I suppose, that it is the same with Task.Delay, but I'm not sure.

MSDN says for Task.Delay only:

Creates a task that will complete after a time delay

Therefore the question: Where (in which synchronization context) runs Task.Delay?


回答1:


Task.Delay doesn't run anywhere. It just creates a task that completes after the specified time. Unlike Task.Run it's not accepting a delegate of yours to run somewhere. Most tasks won't represent the execution of some method on another thread. Task.Run is one of few methods that do that.



来源:https://stackoverflow.com/questions/53377961/synchronization-context-for-task-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!