title: In Quartz.net, how do I prevent a job running concurrently when using a single IJob?
body: <p>I am using Quartz.Net within a Windows Service to handle the scheduling of various jobs that I will be running. These jobs live inside of a database and each job is handled by a factory method inside of a separate class library.</p>
  
  <p>I want to prevent the scheduler from running more than 1 of my jobs at a single time, however I can't use the <code>[DisallowConcurrentExecution]</code> attribute because I only have a single <code>IJob</code> in the scheduler - my factory method in a separate library handles the decision of what job to run.</p>
  
  <p>Below is my single <code>IJob</code>:</p>
  
  <pre><code>    public void Execute(IJobExecutionContext context)
      {
          JobDataMap dataMap = context.JobDetail.JobDataMap;
          int jobId = dataMap.GetInt("JobId");
          logger.InfoFormat("Job {0} has been triggered.", jobId);
  
          //Create a new Job Instance
          JobInstance jobInstance = new JobInstance()
          {
              CreateDate = DateTime.UtcNow,
              ExecutionState = ExecutionState.Running,
              CreateSource = "Agent Scheduler Service",
              Job = new Job() { Id = jobId }
          };
  
          middlewareRepository.CreateJobInstance(jobInstance);
          var job = jobFactory.GetJobImplementation(jobInstance);
  
          //execute the job
          job.Execute();
          logger.InfoFormat("Job {0} has been executed.", jobId);
      }
  </code></pre>
  
  <p>In this, there is a <code>jobId</code> which is my key for my job that I want to only allow a single instance to run at any given time.</p>
  
  <p>This is how I load the jobs:</p>
  
  <pre><code>protected void LoadJobs()
  {
      logger.Info("Loading jobs.");
      var jobs = middlewareRepository.GeActiveJobs();
  
      foreach (var job in jobs)
      {
          IJobDetail jobDetail = JobBuilder.Create&lt;JobDespatcher&gt;()
              .WithIdentity(job.Description)
              .UsingJobData("JobId", job.Id)
              .Build();
  
          ITrigger trigger = TriggerBuilder.Create()
              .WithCronSchedule(job.CronExpression)
              .Build();
  
          scheduler.ScheduleJob(jobDetail, trigger);
          logger.InfoFormat("Job with id {0} ({1}) has been scheduled.", job.Id, job.Description);
      }
  }
  </code></pre>
  
  <p>Is there a way within Quartz.net to prevent the same job from running twice based on a key or a piece of data?</p>