I am sending 'Async' emails.
I use a common 'Async' function to call the Email function as I don't need to wait for the response for the emails.
public Task SendAsync(....)
{
....
return mailClient.SendMailAsync(email);
}
I need to call it from both async
and sync
functions.
Calling from async function
public async Task<ActionResult> AsyncFunction(...)
{
....
EmailClass.SendAsync(...);
....
// gives runtime error.
// "An asynchronous module or handler completed while an asynchronous operation was still pending..."
// Solved by using 'await EmailClass.SendAsync(...);'
}
Calling from sync function
public ActionResult syncFunction(...)
{
....
EmailClass.SendAsync(...);
....
// gives runtime error.
// "An asynchronous operation cannot be started at this time..."
// Solved by converting the function as above function
}
Both the functions give runtime error which is then solved by using await
keyword in async function.
But by using await
it defeats my purpose of running it on background without waiting for response
.
How do i call the async function without waiting for the response?