本文介绍了是否MvcMailer SendAsync阻止ASP.NET MVC请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道,如果在SmtpClientWrapper块MvcMailer SendAsync方法的ASP.NET MVC请求?纵观MvcMailer维基和code,我会说是的。

Does anyone know if the MvcMailer SendAsync method in SmtpClientWrapper blocks a ASP.NET MVC Request? Looking at the MvcMailer wiki and the code I would say yes.

所以,我仍然需要使用像WebBackgrounder作为disussed here一个安全和真正的异步发送邮件在我的MVC应用程序?

So I would still need to use something like WebBackgrounder as disussed here for a safe and truly asynchronous mail send in my MVC app?

我在寻找一个明确的答案,谢谢。

I'm looking for a definitive answer thanks.

推荐答案

下载MvcMailer并运行自己的测试,我可以证实,确实SendAsync阻止ASP.NET请求,直到完成后。

After downloading MvcMailer and running my own tests I can confirm that SendAsync does block a ASP.NET request until completion.

微软证实了这一行为,https://connect.microsoft.com/VisualStudio/feedback/details/688210/smtpclient-sendasync-blocking-my-asp-net-mvc-request

Microsoft confirms this behaviour https://connect.microsoft.com/VisualStudio/feedback/details/688210/smtpclient-sendasync-blocking-my-asp-net-mvc-request

SendAsync()调用SynchronizationContext.OperationStarted(),它是一个提示,未处置HttpContext实例的(或者甚至进步的请求),直到异步操作已完成。

"SendAsync() calls SynchronizationContext.OperationStarted(), which is a cue to not dispose of the HttpContext instance (or even progress the request) until the asynchronous operation has completed."

由于MvcMailer刚刚从System.Net.Mail包装SendAsync从同样的限制受到影响。

As MvcMailer just wraps SendAsync from System.Net.Mail it suffers from the same limitations.

异步发送邮件的正确方法是使用类似WebBackgrounder,因为那是一个完全后台运行(所以如果你使用SendAsync或发送没关系)。

The correct way to send email asynchronously is to use something like WebBackgrounder, as then it is a totally background operation (so it doesn't matter if you use SendAsync or Send).

为了简单起见,你也可以使用Ajax来发送电子邮件,但是这具有客户端,而不是服务器操作的缺点。

To keep things simple you could also use Ajax to send the email, but this has the disadvantage of being a client rather than a server operation.

这篇关于是否MvcMailer SendAsync阻止ASP.NET MVC请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 11:58