SendMailAsync : An asynchronous module or handler completed while an asynchronous operation was still pending

不想你离开。 提交于 2019-12-05 01:53:15

Your call hierarchy is broken. You shouldn't use async void, that is ment for event handlers only, use async Task instead:

public static Task SendEmailAsync(MessageContent messageContent, string emailBody)
{
   SmtpClient smtpClientNoSend = new SmtpClient();
   return smtpClientNoSend.SendMailAsync(mailMessage);
}

public async Task<ActionResult> Register()
{
   await SendEmailAsync();
}

private Task SendEmailAsync()
{
   return SMTPEmail.SendEmailAsync(msg, output.ToString());
}

Side note - I'm not sure why you have so many SendMail methods, You could narrow them down to a single method call.

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