Reputation: 18068
I have a method
public void SendReports(){refering to Entity Framework database and sending some records via mail}
I would like to invoke this method everyday at 04:00. Is there any solution built in ASP .NET MVC 5.1 to achieve that? I can't find any info about it but it seems pretty common thing people would demand.
WebApplication will be deployed to Microsoft Azure.
Upvotes: 1
Views: 1863
Reputation: 25695
This really isn't suppose to be done by ASP.NET engine.
Instead make a windows service(or an executable) that relies on some sort of messaging(MSMQ?) between ASP.NET engine and the windows service(or some sort of data in the database) that does this for you.
Pick the right guy for the job(Mafia style :-P)
Edit:
Azure? Scheduler?
And also the simplest I know on Windows Azure: Web Jobs
Upvotes: 4
Reputation: 127543
ASP.NET can't do what you want to do by itself. The IIS AppPool your webiste is running under will shut itself down after a idle period so you don't know if your code will be running at 4:00 or not. You need a scheduled service outside of your ASP.NET site that triggers your code to run and is not dependant on your IIS AppPool running. You can create services that do exactly that in the azure portal under App Services->Scheduler.
What you will need to do is have a controller that when called will run SendReports
. You then have the scheduled job in azure call the URL for that controller at 4:00 every day.
Upvotes: 3