title: How to schedule task using Quartz.net 2.0?
body: <p>I am trying to schedule a task using Quartz.net 2.0 in ASP.NET MVC 4 application, but i can not get the task to be executed.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public class ScheduleTaskConfig
  {
      public static void StartScheduler()
      {
          ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
  
          IScheduler scheduler = schedulerFactory.GetScheduler();
  
          JobKey emailSenderTaskKey = new JobKey("emailSenderTask", "email");
          IJobDetail emailSenderTask = JobBuilder.Create&lt;QueuedEmailsSendTask&gt;()
              .WithIdentity(emailSenderTaskKey)
              .Build();
  
          TriggerKey emailSenderTriggerKey = new TriggerKey("emailSenderTrigger", "email");
          ITrigger emailSenderTrigger = TriggerBuilder.Create()
              .WithIdentity(emailSenderTriggerKey)
              .WithSimpleSchedule(s =&gt; s.RepeatForever().WithIntervalInSeconds(5))
              .StartNow()
              .Build();
  
          scheduler.ScheduleJob(emailSenderTask, emailSenderTrigger);
          scheduler.Start();
      }
  }
  </code></pre>
  
  <p>It is called in global.asax application start</p>
  
  <pre><code>protected void Application_Start()
  {
      ScheduleTaskConfig.StartScheduler();
      ...
  }
  </code></pre>
  
  <p>And here is the class that implements the IJob interface:</p>
  
  <pre><code>public class QueuedEmailsSendTask : IJob
  {
      private IQueuedEmailsService _queuedEmailsService { get; set; }
      private IEmailSenderService _emailSenderService { get; set; }
  
      public QueuedEmailsSendTask(IQueuedEmailsService queuedEmailsService, IEmailSenderService emailSenderService)
      {
          this._queuedEmailsService = queuedEmailsService;
          this._emailSenderService = emailSenderService;
      }
  
      public void Execute(IJobExecutionContext executeContext)
      {
          //do stuff ...
      }
  }
  </code></pre>
  
  <p>I placed a breakpoint at the beginning of the Execute method, but the debugger does not stop there. What am i doing wrong?</p>
  
  <p><strong>UPDATE:</strong>
  It has something to do with the class that implements the IJob interface not having a default constructor.
  It works, if I modify the constructor like this:</p>
  
  <pre><code>public QueuedEmailsSendTask()
  {
  }
  </code></pre>
  
  <p>But I need to be able to inject my dependencies. I am using the Autofac IoC container.</p>