The wait statement is applied to a task in an asynchronous method to pause the method until the expected task completes. The task is an ongoing job.
It seems you do not want to wait for the SendMails result. Think of async and wait as tools for using asynchronous APIs. In particular, it is very useful to be able to "wait" for the result of an "asynchronous" task. However, if you do not need the result of your "async" task (for example, SendMails), you do not need to "wait" for the result (ie Boolean).
Instead, you can simply use Task.Run to invoke your asynchronous task.
[HttpPost] public async Task<ActionResult> Save(ContactFormViewModel contactFormVM) { if (domain.SaveContactForm(contactFormVM) > 0) {// saves data in database Task.Run(() => SendMails(contactFormVM)); return Json("success"); } return Json("failure"); } public void SendMails(ContactFormViewModel contactFormVM) { domain.SendContactFormUserMail(contactFormVM); domain.SendContactFormAdminMail(contactFormVM); }
source share