I have following Scenario,
public class User
{
public static async Task<bool> UserRegistration()
{
// So Many Async Async Await Methods
bool IsRegistrationSuccess = await RegisterUser();
if(IsRegistrationSuccess)
{
await SendSMS(); // Fire And Forget
await SendEmail(); // Fire And Forget
return true;
}
return false;
}
private static async Task SendSMS()
{
string URL = "http://www.example.com/dsad";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(URL);
}
}
private static async Task SendEmail()
{
string emailMessage = "Some Email";
await EmailService.Send(emailMessage);
}
}
I want to call SendSMS();
and SendEmail();
without await. Don't want to wait for the result.
If I do So gives the warning,
because this call is not awaited execution of the current method continues before the call is completed. Consider applying an operator to the result of the call.
So, question is, If the UserRegistration()
method returns before completion of SendSMS()
OR SendEmail()
, Does it fire the exception? And Is it good practice to make Fire and Forget call in Async Await Methods?