I have many tasks (recorded in a database with scheduled time) that need to be run on different times on different dates randomly, and each task will take a long time to process.
Every week there will be new more tasks coming up. What is the best solution to automatically execute all these tasks at an exact time?
Using an ASP.NET application to execute recurring background tasks is usually a bad idea as Phil Haack explained in his blog post.
So you could write a console application that will query your database and perform the necessary tasks. Then simply use the Windows Scheduler to execute this application at the required intervals. As an alternative you could implement the task in your ASP.NET application and have the console application simply fire an HTTP Request to the corresponding controller action.
If you don’t have access to your server and cannot host anything else than an ASP.NET application then you should be perfectly aware of the consequences of going with this approach (as explained in the aforementioned article). So one approach would be to use a library such as Quartz.NET to schedule the execution of some code at regular intervals.