gpt4 book ai didi

asp.net-core - 什么取代了 ASP.NET Core 中的 SynchronizationContext?

转载 作者:行者123 更新时间:2023-12-03 17:02:59 25 4
gpt4 key购买 nike

ASP.NET Core 没有 SynchronizationContext .

那么如何继续async代码恢复到它开始的地方(原始线程)?

最佳答案

TL;DR 延续不必返回原始线程。

Stephen Cleary 很好地解释了为什么 ASP.NET Core 没有 SynchronizationContext。

When an asynchronous handler resumes execution on legacy ASP.NET, the continuation is queued to the request context. The continuation must wait for any other continuations that have already been queued (only one may run at a time). When it is ready to run, a thread is taken from the thread pool, enters the request context, and then resumes executing the handler. That “re-entering” the request context involves a number of housekeeping tasks, such as setting HttpContext.Current and the current thread’s identity and culture.

With the contextless ASP.NET Core approach, when an asynchronous handler resumes execution, a thread is taken from the thread pool and executes the continuation. The context queue is avoided, and there is no “entering” of the request context necessary. In addition, the async/await mechanism is highly optimized for the contextless scenario. There’s simply less work to do for asynchronous requests.

Read more



我还建议深入研究评论,那里有很多有用的东西。

关于asp.net-core - 什么取代了 ASP.NET Core 中的 SynchronizationContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56059678/

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