title: How to perform periodic work on an ASP.NET MVC website?
body: <p>Once a day, I want my ASP.NET MVC4 website, which may be running on multiple servers, to email a report to me.  This seems like a pretty common thing to want to do, but I'm having a tough time coming up with a good way to do it.</p>
  
  <p>Trying to run a timer on a server to do this work is problematic for a couple of reasons.  If I have multiple servers then I'd have the timer running on all of them (in case a server goes down); I'd need to coordinate between them, which gets complicated.  Also, trying to access the database via Entity Framework from a background thread adds the complication that I must employ a locking strategy to serialize construction/disposal of the DbContext object between the periodic background thread and the "foreground" Controller thread.</p>
  
  <p>Another option would be to run a timer on the servers, but to have the timer thread perform a GET to a magic page that generates and emails the report.  This solves the DbContext problem because the database accesses happen in a normal Controller action, serialized with all of the other Controller accesses to the database.  But I'm still stuck with the problem of having potentially more than one timer running, so I'd need some smarts in the Controller action to ignore redundant report requests.</p>
  
  <p>Any suggestions?  How is this sort of thing normally done?</p>