My requirement is to schedule the reports at a particular time and frequency, i.e. weekly, monthly or daily.
This reports should be mailed at specified time with attachment at which it is scheduled.
Thanks in advance
My requirement is to schedule the reports at a particular time and frequency, i.e. weekly, monthly or daily.
This reports should be mailed at specified time with attachment at which it is scheduled.
Thanks in advance
You could schedule tasks from within your ASP.NET project using the Revalee open source project.
Revalee is a service that allows you to schedule web callbacks to your web application. In your case, you would schedule a callback that would synchronize your data at a specific time. Revalee works very well with tasks that are discrete transactional actions, like updating some database values or sending an automated email message (read: not long running). The code to perform your action would all reside within your app.
To use Revalee, you would:
Install the Revalee Service, a Windows Service, on your server. The Windows Service is available in the source code (which you would compile yourself), in a precompiled version available at the Revalee website, or via Chocolatey.
Use the Revalee client library in your Visual Studio project. (There is an MVC-specific version too.) The client library is available in the source code (which, again, you would compile yourself) or in a precompiled version available via NuGet.
You would register a future callback when your code calls the ScheduleReportTransmission()
method (this example is assuming that you need your action to run 12 hours from now, but it could be any date & time).
Private Sub ScheduleReportTransmission()
Dim callbackTime As DateTimeOffset = DateTimeOffset.Now.AddHours(12.0)
' The callback should be 12 hours from now
Dim callbackUrl As New Uri("http://mywebapp.com/TransmitReport.aspx")
' Register the callback request with the Revalee service
RevaleeRegistrar.ScheduleCallback(callbackTime, callbackUrl)
End Sub
When Revalee calls your application back, your app would perform whatever action you have coded it to do. You do this by adding the following method call (TransmitReport()
) to your TransmitReport.aspx
page handler, à la:
Private Sub TransmitReport()
' TODO Lookup the report information and send the email
' ...
Return
End Sub
I hope this helps.
Note: The code example above uses a synchronous version of ScheduleCallback()
, the Revalee client library also supports asynchronous calls à la:
RevaleeRegistrar.ScheduleCallbackAsync(callbackTime, callbackUrl)
In case it was not clear above, the Revalee Service is not an external 3rd party online scheduler service, but instead a Windows Service that you install and fully control on your own network. It resides and runs on a server of your own choosing, most likely your web server (but this is not a requirement), where it can receive callback registration requests from your ASP.NET application.
Disclaimer: I was one of the developers involved with the Revalee project. To be clear, however, Revalee is free, open source software. The source code is available on GitHub.
There is a great framework called Hangfire that you can use to schedule tasks in .net:
http://hangfire.io/
You'll need to create your method for running the report and sending the email but you can schedule that task easily with the hangfire framework.
For other alternatives take a look at this blog entry by Hanselman: http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx