Does MvcMailer SendAsync block a ASP.NET MVC Request?

倾然丶 夕夏残阳落幕 提交于 2019-12-07 06:44:49

问题


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.

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.


回答1:


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

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

"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."

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

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).

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.



来源:https://stackoverflow.com/questions/10250042/does-mvcmailer-sendasync-block-a-asp-net-mvc-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!