Make sendPostFailMessage Async?

Johnathan Simpson 586 Reputation points

Hello - how can I make this method async?

public class SendEmail
    public void sendPostFailMessage()
    {       var apiKey = "";

        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("", "Test");
        var subject = "Error";
        var to = new EmailAddress("", "Testtest");
        var plainTextContent = "and easy to do anywhere, even with C#";
        var htmlContent =
            "Hello, <br><br> There has been an is";
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = client.SendEmailAsync(msg).Wait(10000);

public class StartService : IStartService
    private readonly SendEmail _sendEmail;
    public async Task GenerateAndSendJson()
        foreach (var item in fromDatabase)
            Console.WriteLine("Sending data");

        Console.WriteLine("Process finish");
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,354 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 26,161 Reputation points

    and since I await the response in the sendPostFailMessageAsync() method, I do not need to await it in the calling method of GenerateAndSendJson()? Is that an accurate statement?

    Yes. The calls must be asynchronous from bottom to top. This information is openly covered in the linked documentation.

    0 comments No comments