I have an ASP.NET MVC4 application. Suppose that I wanted to execute some code (such as emailing a user) 2 days after a user has signed up.One way is to have code executed on every request which scans the database for users and their sign-up time and execute code based on that. This seems messy and it depends on people visiting the application frequently.Another way is to write a separate application that runs on the server 24/7 and performs the checking itself, perhaps scanning the database at 12:00am every day and performing its own code.What's the good way to go about this?
How do I make my ASP.NET application take an action based on time?
asp.net mvc;sql server
A scheduled task triggered by either the Task Scheduler or Sql Server is the way to go here. But if you really want to manage it within your webapp, you might want to look at something like Quartz.NET. It will let you do scheduled tasks from the CLR. Then your challenge is how do I make sure the AppDomain stays up to run the tasks.Another way to do it as a scheduled task yet keep most of the smarts on the server is to make it a task that can be called over HTTP with some sort of authorization key. This lets you write a relatively simple program to call it -- if not a simple shell script -- and to keep most of the complexity in the web app which is likely already capable of running the task.Either way rolling your own task manager is really a path fraught with peril.