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
我在GitHub上偶然发现了一个问题(https://github.com/HTBox/allReady/issues/1313),他们讨论了将configurewait (false)从代码中删除,并在ASP中声明这一点。网络核心
the call to
ConfigureAwait(false)
is redundant and does nothing对configurewait (false)的调用是冗余的,没有任何作用
Best I could find here is a “side note” in an answer (from Stephen Cleary, https://*.com/a/40220190/2805831) telling that
我能在这里找到的最好的答案是一个“副注”(来自Stephen Cleary, https://*.com/a/40220190/2805831)
ASP.NET Core no longer has a "context"
ASP。NET Core不再有“上下文”
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?
所以,配置等待(false)在ASP中是真的没有必要的。NET核心(即使使用完整的。NET框架)?在某些情况下,它在性能上有真正的提高吗?在结果/语义上有什么不同吗?
EDIT: Is it different in this aspect if I am hosting it as a console application or in IIS?
编辑:如果我将它作为控制台应用程序或IIS托管,它在这方面有什么不同吗?
1 个解决方案
#1
15
ConfigureAwait
only has effects on code running in the context of a SynchronizationContext
which ASP.NET Core doesn't have (ASP.NET "Legacy" does).
配置等待只对在同步上下文环境中运行的代码产生影响。NET核心没有(ASP)。净“遗产”。
General purpose code should still use it because it might be running with a SynchronizationContext
.
通用代码仍然应该使用它,因为它可能与SynchronizationContext一起运行。
ASP.NET Core SynchronizationContext
ASP。网络核心SynchronizationContext
#1
15
ConfigureAwait
only has effects on code running in the context of a SynchronizationContext
which ASP.NET Core doesn't have (ASP.NET "Legacy" does).
配置等待只对在同步上下文环境中运行的代码产生影响。NET核心没有(ASP)。净“遗产”。
General purpose code should still use it because it might be running with a SynchronizationContext
.
通用代码仍然应该使用它,因为它可能与SynchronizationContext一起运行。
ASP.NET Core SynchronizationContext
ASP。网络核心SynchronizationContext