You can use the Timer class to run the scheduler inside your Azure Web Site project. This way, you can have everything encapsulated inside your ASP.NET MVC project.
Info about Timer class: http://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx
I tested this in a MVC project on Azure Web Site and can confirm that it works. To get this set up, start the timer inside Application_Start() of Global.asax.cs:
private Timer _timer;
protected void Application_Start()
{
_timer = new Timer(1 * 60 * 1000); // 1 minute
_timer.Elapsed += (sender, e) => ScheduledTask.Process();
_timer.Enabled = true;
// other code goes here
}
In my example, the timer calls ScheduledTask.Process() every minute. Here is what my ScheduledTask class looks like:
public class ScheduledTask {
public int Id { get; set; }
public DateTime Time { get; set; }
public static void Process() {
using (var db = new ApplicationDbContext()) {
db.ScheduledTasks.Add(new ScheduledTask {
Time = DateTime.Now
});
db.SaveChanges();
}
}
}
In Process(), you can do whatever you want, but I'm just creating an entry in the database to test whether this works. I'll keep this task working for about a day so and you can see the results here:
http://contactmanager1.azurewebsites.net/ScheduledTask
Update
It turns out that this isn't the best way to set up scheduled tasks, because this timer dies when the application pool times out (due to low activity on the site). The timer automatically starts up again when application pool starts up again, but for low volume sites, this isn't a reliable solution.