How can I make my MediatR notification handler fire and forget?
My sample code:
public class BackupDatabase : INotification {}
public class BackupDatabaseNotificationHandler : INotificationHandler<BackupDatabase>
{
public async Task Handle(BackupDatabase notification, CancellationToken cancellationToken)
{
await Task.Delay(100000000);
}
}
public async Task<IActionResult> SomeAction()
{
await _mediator.Publish(new BackupDatabase());
return Json(true);
}
I know one way is to use the Task.Factory.StartNew, But is there another way?