5

I am using Quartz.Net to schedule task. I have tried like wise.

Started a visual studio console application and added two reference i.e Quartz.dll and Common.Logging.dll along with System.Web.Services;

Then i coded a little bit for a normal task as provided on the link http://simplequartzschedulerincsharp.blogspot.com/ (They are claiming that its working)

But as soon as i tried to Run the program it gave error as "Missing reference to Quartz.all" but i have added this already.

Why this is happening ?

Also somewhere i noted that one need to install the Quartz.Server.Service to use it etc. etc.

Please guide me and please dictate me a simple but working example and points i am missing ?

ItsLockedOut
  • 229
  • 1
  • 4
  • 17
  • is *.all from "Missing reference to Quartz.all" a bug or mistype? :) – Răzvan Flavius Panda Jan 16 '12 at 16:21
  • @RăzvanPanda : Its like everything is fine while coding..i have added Quartz.dll but when i try to run (using F5) it stops and says "Namespance Quartz can not be found..are u Missing reference to Quartz" ? – ItsLockedOut Jan 17 '12 at 10:48

1 Answers1

16

The example on the site is probably outdated.

I made some modifications to the classes used and now it runs:

using System;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Triggers;
// Necessary references:
// Quartz dll
// Common.Logging
// System.Web
// System.Web.Services

namespace QuartzExample
{
    class Program
    {
        private static IScheduler _scheduler;

        static void Main(string[] args)
        {
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            _scheduler = schedulerFactory.GetScheduler();
            _scheduler.Start();
            Console.WriteLine("Starting Scheduler");

            AddJob();
        }

        public static void AddJob()
        {
            IMyJob myJob = new MyJob(); //This Constructor needs to be parameterless
            JobDetailImpl jobDetail = new JobDetailImpl("Job1", "Group1", myJob.GetType());
            CronTriggerImpl trigger = new CronTriggerImpl("Trigger1", "Group1", "0 * 8-17 * * ?"); //run every minute between the hours of 8am and 5pm
            _scheduler.ScheduleJob(jobDetail, trigger);
            DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc();
            Console.WriteLine("Next Fire Time:" + nextFireTime.Value);
        }
    }

    internal class MyJob : IMyJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Console.WriteLine("In MyJob class");
            DoMoreWork();
        }

        public void DoMoreWork()
        {
            Console.WriteLine("Do More Work");
        }
    }

    internal interface IMyJob : IJob
    {
    }
}
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • Where can i find rules for triggers? – Johnny_D May 18 '12 at 14:00
  • @Johnny_D: I think you can find information about that in the [tutorial](http://quartznet.sourceforge.net/tutorial/index.html). If you download the [source code](http://sourceforge.net/projects/quartznet/files/quartznet/) you will also find some interesting example task configurations. hth – Răzvan Flavius Panda Feb 05 '13 at 16:46
  • The previous example only works on version 2.6.1. If you download the nugget package the latest version by default is 3.2.1. The online examples on the tutorial pages are out of date. – Juan Acosta Feb 09 '21 at 23:19