title: Using Quartz.NET as a Windows Service
body: <p>I am writing a scheduler component and I was planning to use Quartz.net.  My requirements are:</p>
  
  <ol>
  <li>Have the scheduler running 24x7 (stopping/failing is acceptable, it would just need to start again)</li>
  <li>Be able to see what jobs/triggers are scheduled via a web page</li>
  <li>Be able to add new jobs/triggers via a web page</li>
  </ol>
  
  <p><br>
  Since I need a scheduler running constantly, I planned to have a Windows service.  Unfortunately, there does not appear to be any way to have the web pages interact with the scheduler running in the Windows service.  I attempted to retrieve an instance with the following code put together from examples by <a href="http://geekswithblogs.net/TarunArora/archive/2013/01/19/quartz.net-windows-service-on-server-important-configuration-steps-to-remember.aspx" rel="nofollow">Turan Arora</a>:</p>
  
  <pre><code>        NameValueCollection properties = new NameValueCollection();
          properties["quartz.scheduler.instanceName"] = "ServerScheduler";
  
          // set thread pool info
          properties["quartz.threadPool.threadCount"] = "0";
  
          // set remoting expoter
          properties["quartz.scheduler.proxy"] = "true";
          properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
  
          // get a reference to the scheduler
          ISchedulerFactory sf = new StdSchedulerFactory(properties);
          IScheduler sched = sf.GetScheduler();
  </code></pre>
  
  <p><br>
  Going this route gives me an error saying:  "Scheduler with name 'ServerScheduler' already exists."  (ServerScheduler is the default scheduler name.)  After some reading, it appears that the solution is to implement a singleton pattern to instanciate and return this instance throughout the lifecycle of the scheduler.</p>
  
  <p>This does not seem like the ideal solution because I wanted two pieces--a scheduler Windows service and a web site.  Clearly the web site should not own the scheduler because for one thing it may or may not be in use 24x7 and I need the scheduled jobs to be able to execute 24x7.  Second, I don't think I want my web site communicating back to a Windows service to get a reference to the scheduler to get this information.</p>
  
  <p>I believe I am misunderstanding the architecture using Quartz.net in this situation.  But, if I am correct, maybe the solution is to maintain a relational data store that Quartz.net can read to get its jobs, and the web site can also read to see what is executing.  I want a relational data store to persist the jobs and triggers anyway, so maybe this is the best means of providing the data between the two applications?</p>