public Task <bool> Send(MailMessage mMailMessage) { EmailUtils.SendEmail(mMailMessage, sentSuccesfully => { if (!sentSuccesfully) { return; } OnSent(mMailMessage); }); return(Task.FromResult(true)); }
// tis method is void - fire and forget! private async void OnSend(MailMessage mMailMessage) { string filename = await SaveEmail(mMailMessage); bool cancelRequest = false; try { await Task.Delay(_sendDelay, _endProcessingToken.Token); } catch (TaskCanceledException e) { _logger.Trace("A request to cancel message send received... {0}", mMailMessage.Subject); cancelRequest = true; } if (cancelRequest) { return; } EmailUtils.SendEmail(mMailMessage, sentSuccesfully => { if (!sentSuccesfully) { return; } try { File.Delete(filename); OnSent(mMailMessage); } catch (Exception e) { _logger.FatalException( "File could not be removed from queue", e); } _logger.Trace( "Processed - delayed email sent. {0}", filename); }); }