title: Use System.Threading.Timer or Quartz in an ASP.NET
body: <p>I want my ASP.MVC application to function as a scheduler for background tasks.  The HttpApplication-subclassed class has the following code:</p>
  
  <pre><code>public class MvcApplication : System.Web.HttpApplication
  {
      private Timer Timer;
      protected void Application_Start()
      {
          if (Timer == null)
          {
              TimerCallback cb = OnTimerElapsed;
              AutoResetEvent autoEvent = new AutoResetEvent(false);
              Timer = new Timer(cb, autoEvent, INITIAL_DELAY, TIMER_INTERVAL);
          }
      }
  
      private void OnTimerElapsed(Object stateInfo)
      {
          //perform background task
      }
  }
  </code></pre>
  
  <p>In addition, instead of using System.Threading.Timer, I also replace it by Quartz-equivalent code, but it also stops firing after a while.</p>
  
  <p>So this begs the question, is Application_Start() the right place or is there a better place? </p>
  
  <p>Both Timer and Quartz approaches work.  But with Quartz,  it seems like for an interval of 1 minute, after 20 intervals (20 minutes), the trigger no longer fires.  With Timer, I am not sure after how many intervals that the trigger stops firing.</p>