I have a process I would like to run in the background. This is executed with a click of an action link.
Action to call:
public async Task
This however waits for the full 10 seconds before redirecting me to my "Index, Home" action.
Right, that's because await asynchronously waits for the operations completion. It will yield the thread back to the pool until the operation completes.
How do I get the application to return to this action, while the waitTimer is executing in the background?
Task.Run is dangerous in the fact it doesn't register work with IIS which can lead to problems. Instead, you can use BackgroundTaskManager or HangFire which register it's execution with ASP.NET:
BackgroundTaskManager.Run(() => { waitTimer() };
return RedirectToAction("Index", "Home");