title: Quartz.net Simple Example
body: <p>I'm trying to find a simple Quartz.Net example where when a button is clicked, it kicks off the Quartz.Net functionality. </p>
  
  <p>I was able to take the Quartz.Net example (console application) and change some things to produce this (SimpleExample.cs):</p>
  
  <pre><code>    public virtual void Run()
      {
          ISchedulerFactory sf = new StdSchedulerFactory();
          IScheduler sched = sf.GetScheduler();
  
          DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTime.UtcNow);
          DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 10);
  
          IJobDetail job = JobBuilder.Create&lt;HelloJob&gt;()
              .WithIdentity("job1", "group1")
              .Build();
          ITrigger trigger = TriggerBuilder.Create()
              .WithIdentity("trigger1", "group1")
              .StartAt(runTime)
              .WithCronSchedule("5 0/1 * * * ?")
              .Build();
  
          sched.ScheduleJob(job, trigger);
  
          sched.Start();
  
      }
  </code></pre>
  
  <p>But I'm a little confused as to how one triggers this from a button click. I thought I could do something like this:</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
       code here....
      }
  </code></pre>
  
  <p>But that didn't work.</p>
  
  <p>I reviewed the following websites, but not all were helpful in relation to starting this from a button click.</p>
  
  <p><a href="http://www.mkyong.com/java/quartz-scheduler-example/" rel="noreferrer">http://www.mkyong.com/java/quartz-scheduler-example/</a>
  - Java, so hard for me to understand the difference (I'm new to all this!).</p>
  
  <p><a href="http://www.hardcodet.net/2010/01/lightweight-task-slash-job-scheduling-with-silverlight-support" rel="noreferrer">http://www.hardcodet.net/2010/01/lightweight-task-slash-job-scheduling-with-silverlight-support</a>
  - This was helpful, but it is unclear to me how Silverlight works with a regular .Net Form. Seems like an entirely different project. </p>
  
  <p>///// </p>
  
  <p>Additional changes:  10/14/2011</p>
  
  <p>I reviewed the suggested code and found the following link with another (simple) example. 
  <a href="http://simplequartzschedulerincsharp.blogspot.co.uk/" rel="noreferrer">http://simplequartzschedulerincsharp.blogspot.com/</a></p>
  
  <p>I went ahead and built out a simple form with a few changes to the author's code as follows:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using Quartz;
  using Quartz.Impl;
  
  //http://simplequartzschedulerincsharp.blogspot.com/
  
  namespace QuartzExampleWF
  {
      public partial class Form1 : Form
      {
          private static IScheduler _scheduler;
  
          public Form1()
          {
              InitializeComponent();
  
              ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
              _scheduler = schedulerFactory.GetScheduler();
  
              AddJob();
          }
          public static void AddJob()
          {
              IMyJob myJob = new MyJob();
              JobDetail jobDetail = new JobDetail("Job1", "Group1", myJob.GetType());
              CronTrigger trigger = new CronTrigger("Trigger1", "Group1", "5 0/1 * * * ?");
              _scheduler.ScheduleJob(jobDetail, trigger);
              DateTime? nextFireTime = trigger.GetNextFireTimeUtc();
          }
          private void button1_Click(object sender, EventArgs e)
          {
              _scheduler.Start();
  
          }
  
          internal class MyJob : IMyJob
          {
              public void Execute(JobExecutionContext context)
              {
                  DateTime now = DateTime.Now;
  
                  DoMoreWork();
              }
  
              public void DoMoreWork()
              {
                  //more code...
              }
          }
          internal interface IMyJob : IJob
          {
          }    
      }
   }
  </code></pre>
  
  <p>Ive never done a internal class before and ran into the issue of referencing a textbox within. For example, I am trying to do the following:</p>
  
  <pre><code>      public void Execute(JobExecutionContext context)
          {
              DateTime now = DateTime.Now;
              this.textbox1 = Now.value;
              DoMoreWork();
          }
  </code></pre>
  
  <p>But I cannot reference a textbox. I would have the same issue with a datagrid or a toolStripStatusLabel. What is the best way to access objects like a textbox or a toolStripStatusLabel under the above code?</p>