ASP.NET不关心客户端应用程序的上下文或线程吗?如果是这样,AspNetSynchronizationContext的目的是什么?我不觉得在操作本身放置一个ConfigureAwait.有些东西似乎错了.有人可以解释吗
public async Task<ActionResult> AsyncWithBackendtest() { var result = await BackendCall().ConfigureAwait(false); var server = HttpContext.Server; HttpContext.Cache["hello"] = "world"; return Content(result); }
解决方法
Stephen Toub mentions this in an MSDN article:
Windows Forms isn’t the only environment that provides a
SynchronizationContext-derived class. ASP.NET also provides one,
AspNetSynchronizationContext,though it’s not public and is not meant
for external consumption. Rather,it is used under the covers by
ASP.NET to facilitate the asynchronous pages functionality in ASP.NET
2.0 (for more information,see msdn.microsoft.com/msdnmag/issues/05/10/WickedCode). This
implementation allows ASP.NET to prevent page processing completion
until all outstanding asynchronous invocations have been completed.
Stephen Cleary’s article from last year提供了有关同步上下文的更多细节.
图4特别表明它没有WinForms / WPF的“特定线程”行为,但整个事情是一个很好的阅读.
If multiple operations complete at once for the same application,AspNetSynchronizationContext will ensure that they execute one at a time. They may execute on any thread,but that thread will have the identity and culture of the original page.
原文地址:https://www.jb51.cc/aspnet/250652.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。