与ASP.NET Core相关的ConfigureAwait(false)? [英] ConfigureAwait(false) relevant in ASP.NET Core?

查看:107
本文介绍了与ASP.NET Core相关的ConfigureAwait(false)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了一个问题( 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"

因此,是 ConfigureAwait(false) ASP.NET Core 中真的不必要(即使使用完整的.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没有(

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

这篇关于与ASP.NET Core相关的ConfigureAwait(false)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆