这里引用了 Jeffrey Richter 的“CLR via C#”一书:
** Starting a New Task Automatically When Another Task Completes**
...calling Wait or querying a task’s Result property when the task has not yet finished running will most likely cause the thread pool to create a new thread, which increases resource usage and hurts scalability.
线程池为什么要新建线程?
最佳答案
在 native 代码中,您首先会使用 CreateThreadpoolWork 创建一个工作项然后使用 WaitForThreadpoolWorkCallbacks 等待它功能。
在 .NET 世界中,我会使用 TPL,创建一个任务,然后是一个 continuation task .将其与 TPL 相结合 TaskScheduler应该会给你想要的效果。
关于c# - 查询任务的 Result 属性导致线程池创建一个新线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5566017/