You may want to take a look at the Revalee open source project.
You can use it to schedule web callbacks at specific times. In your case, you could schedule a web callback (10 minutes in the future). When your application receives the callback, it can schedule the next 10 minute callback. When your ASP.NET application launches for the very first time, then you would schedule the first web callback. Since you web application is being called back you do not need to worry about IIS unloading your web application (which it, of course, will).
For example using Revalee, you might do the following:
Register a future (10 minutes from now) callback when your application launches via the ScheduleTenMinuteCallback()
method (see below).
private DateTimeOffet? previousCallbackTime = null;
private void ScheduleTenMinuteCallback()
{
// Schedule your callback 10 minutes from now
DateTimeOffset callbackTime = DateTimeOffset.Now.AddMinutes(10.0);
// Your web service's Uri
Uri callbackUrl = new Uri("http://yourwebapp.com/ScheduledCallback.aspx");
// Register the callback request with the Revalee service
RevaleeRegistrar.ScheduleCallback(callbackTime, callbackUrl);
previousCallbackTime = callbackTime;
}
When the web scheduled task activates and calls your application back, you perform whatever action you need to do every 10 minutes and you schedule the next callback too. You do this by adding the following method call (CallbackMonitor()
) to your ScheduledCallback.aspx
page handler.
private void CallbackMonitor()
{
if (!previousCallbackTime.HasValue
|| previousCallbackTime.Value <= DateTimeOffset.Now.AddMinutes(-10.0))
{
// Perform your "10 minutes have elapsed" action
// ...do your work here...
// Schedule subsequent 10 minute callback
ScheduleTenMinuteCallback();
}
}
Your point about not using '3rd party online scheduler services' is understood. The Revalee Service is not an external 3rd party online scheduler service, but instead a service (a Windows Service, more specifically) that you install and control fully on your own network. It resides and runs on a server of your own choosing, most likely behind your firewall, where it can receive callback registration requests from your web application on IIS. (It can, of course, be installed on the IIS web server if necessary.)
I hope this helps.
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.
schtasks.exe
is the closest thing tocron
in Windows, which answers the literal question OP asked. – Solanaceous