Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Quartz.net in console application [showing error]? [closed]

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 ?

like image 525
ItsLockedOut Avatar asked Jan 16 '12 15:01

ItsLockedOut


1 Answers

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
    {
    }
}
like image 121
Răzvan Flavius Panda Avatar answered Oct 19 '22 00:10

Răzvan Flavius Panda