Check the below block of code. I need fire and forget behavior while calling sendMail method (i.e. while calling api). With this block of code I'm getting TaskCancelledException sometimes. Please help
private void ProcessMails()
{
while(true)
{
var mailsToBeProcessed = getAllMailsToBeProcessed(alreadySent, numOfMailsToBeProcessed);
freach(var mail in Mails)
{
sendMail("mailsendingApiUrl", mail)
alreadySent++;
}
Thread.Sleep(60000);
}
}
private async void sendMail(string apiEndPoint, MailContent mailContent)
{
using (var client = new HttpClient())
{
await client.PostAsJsonAsync(apiEndPoint, mailContent.ContentId);
}
}
Aucun commentaire:
Enregistrer un commentaire