I have an ASP.NET MVC app written in C#. One of my actions looks like this:
[HttpPost]
public async Task<ActionResult> Save(int id, MyViewModel viewModel)
{
viewModel.SaveToDb();
await Backup.Save(viewModel);
return View(viewModel);
}
...
public class Backup
{
async public static Task Save(IBackup item)
{
// do stuff
}
}
There is actually a lot going on in the Backup.Save function. In fact, await Backup.Save(...)
is currently taking 10 seconds. For that reason, I want to run it in the background (asynchronously) and not (a)wait on it. I thought if I just removed the await
keyword, it would work. However, it does not appear that is the case.
How can I run Backup does save asynchronously in the background so that my users can continue using the app without long wait times?
Thank you!