I have code in ASP.net that sends an email. My application is older using ASP.net Webforms and is not converted over to async methods.
However the method for sending email via SendGrid is async awaitable.
Visual Studio doesn't complain if I use a discard:
_ = SendASendGridMessage()
Would this cause any crash or deadlock if I do this?
Here is the sample code:
public static void SendNew(string toEmail, string subject, string htmlContent, int domainId, int partyId, string category, int itemId)
{
EmailAddress from = new EmailAddress("example@example.com");
EmailAddress to = new EmailAddress(toEmail);
EmailAddress replyTo = new EmailAddress("example@example.com");
htmlContent = $"<html><body>{htmlContent}</body></html>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, null, htmlContent);
_ = SendASendGridMessage(msg, domainId);
}
// Which will then connect with this method later:
// Summary:
// Make a request to send an email through Twilio SendGrid asynchronously.
//
// Parameters:
// msg:
// A SendGridMessage object with the details for the request.
//
// cancellationToken:
// Cancel the asynchronous call.
//
// Returns:
// A Response object.
[AsyncStateMachine(typeof(<SendEmailAsync>d__23))]
public Task<Response> SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default);