I have an ASP.net MVC controller action which needs to do some code (cleanup, sending emails, …) in case the action was successful.
I don’t want to let the user wait in the meantime. So I am wondering if there is a way to execute code AFTER the action has been executed AND the result has been sent to the browser.
Use Tasks, I find them to be easier to use than threads.
http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx
If you are using something like the entity framework, we use an interface we created called INotifySaving and in our datacontext if the entity we are saving implements INotifySaving tat we call the OnSaving method. In OnSaving we will often use tasks to run longer running methods. Hope that helps.