ConfigureAwait(false) 与 ASP.NET Core 相关吗? [英] ConfigureAwait(false) relevant in ASP.NET Core?
问题描述
我偶然发现了一个问题(https://github.com/HTBox/allReady/issues/1313) 在 GitHub 上,他们讨论了从代码中删除 ConfigureAwait(false)
的问题,声称在 ASP.NET Core
I stumbled on an issue (https://github.com/HTBox/allReady/issues/1313) at GitHub where they discussed about taking the ConfigureAwait(false)
out of the code, claiming that, in ASP.NET Core
对ConfigureAwait(false)
的调用是多余的,什么都不做
the call to
ConfigureAwait(false)
is redundant and does nothing
我能在这里找到的最好的答案是一个旁注"(来自 Stephen Cleary,https://stackoverflow.com/a/40220190/2805831) 告诉
Best I could find here is a "side note" in an answer (from Stephen Cleary, https://stackoverflow.com/a/40220190/2805831) telling that
ASP.NET Core 不再有上下文"
ASP.NET Core no longer has a "context"
那么,ASP.NET Core 中是否真的不需要 ConfigureAwait(false)
(即使使用完整的 .Net Framework)?它在某些情况下是否有真正的性能提升或结果/语义上的差异?
So, is ConfigureAwait(false)
really unnecessary in ASP.NET Core (even if using full .Net Framework)? Does it have any real gain in performance in some cases or difference in the result/semantic?
如果我将它作为控制台应用程序或在 IIS 中托管,在这方面是否有所不同?
Is it different in this aspect if I am hosting it as a console application or in IIS?
推荐答案
ConfigureAwait
仅对在 SynchronizationContext
的上下文中运行的代码有影响,而 ASP.NET Core没有(ASP.NETLegacy"有).
ConfigureAwait
only has effects on code running in the context of a SynchronizationContext
which ASP.NET Core doesn't have (ASP.NET "Legacy" does).
通用代码仍应使用它,因为它可能与 SynchronizationContext
一起运行.
General purpose code should still use it because it might be running with a SynchronizationContext
.
ASP.NET Core SynchronizationContext
这篇关于ConfigureAwait(false) 与 ASP.NET Core 相关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!