gpt4 book ai didi

c# - 异步等待和线程

转载 作者:太空狗 更新时间:2023-10-29 20:56:15 25 4
gpt4 key购买 nike

<分区>

我正在使用 async-await 和任务,但我无法理解一件事:

异步任务是否在单独的线程中执行?

正如 msdn 所说 ( Asynchronous programming ):

The async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread.

但是在 ThreadPool 类(ThreadPool Class)描述的备注中:

Examples of operations that use thread pool threads include the following:

When you create a Task or Task object to perform some task asynchronously, by default the task is scheduled to run on a thread pool thread.

所以,现在我不明白 async 任务是否使用单独的线程。请解释一下。谢谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com