Is there any danger in using ConfigureAwait(false) in WebApi or MVC controllers?

前端 未结 4 1992
逝去的感伤
逝去的感伤 2021-01-31 07:43

Say I have two scenarios:

1) WebApi Controller

    [System.Web.Http.HttpPost]
    [System.Web.Http.AllowAnonymous]
    [Route(\"api/regi         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 08:07

    If there's no actual context in a ASP.NET Core application, it should do no harm nor good to add .ConfigureAwait(false) to your awaitable methods into controllers.

    However, if there is a chance that eventually in the future, for whatever reason, there's something like a context to be taken into account as in ASP.NET 4, that would be a different story. We could not risk running in a different context, unless we don't give a damn about it (in which case we could use whatever thread is available for processing, thus possibly improving performance).

    My choice here is to add ConfigureAwait(false) even if it's not used.

提交回复
热议问题