Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple, working example of Quartz.net [closed]

I am looking for a working simple example of Quartz.net for Console application (it can be any other application as long as it simple enough...). And while I am there, is there any wrapper that could help me avoid implementing IJobDetail, ITrigger, etc.

like image 474
Tomer Avatar asked Jan 11 '12 15:01

Tomer


People also ask

How does Quartz Net work?

As per their website: Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems. It's an old staple of many ASP.NET developers, used as a way of running background tasks on a timer, in a reliable, clustered, way.

Is Quartz net open source?

Quartz.Net is a . NET port of the popular Java job scheduling framework. It's an open source job scheduling system that can be used from the smallest apps to the large-scale enterprise systems.

How do I enable Quartz logging?

Using Quartz with slf4j-simple The slf4j-simple is so simple, you don't even need to configure anything. Just add the dependency into your Maven project, and you are good to go! Then it will default logging INFO level messages. If you want to see DEBUG verbose messages, then add this System Property -Dorg.

Does Quartz Net have a UI?

I recently published new alternative web UI for Quartz.NET. You can manage jobs, triggers, calendars and most of the API which IScheduler provide. It is pluggable into existing OWIN and ASP.NET Core application or it creates embedded web server on it own.


1 Answers

There is a guy who made the exact same observation as you, and he has published a blog post with a simple working example of a Quartz.net Console application.

The following is a working Quartz.net example that is built against Quartz.net 2.0 (Latest). What this job does is write a text message, “Hello Job is executed” in the console every 5 sec.

Start a Visual Studio 2012 project. Select Windows Console Application. Name it Quartz1 or what ever you like.

Requirements Download Quartz.NET assembly using NuGet. Right click on project, select “Manage Nuget Packages”. Then search for Quartz.NET. Once found select and install.

using System;
using System.Collections.Generic;
using Quartz;
using Quartz.Impl;
     
namespace Quartz1
{
    class Program
    {
        static void Main(string[] args)
        {
        // construct a scheduler factory
        ISchedulerFactory schedFact = new StdSchedulerFactory();
         
        // get a scheduler, start the schedular before triggers or anything else
        IScheduler sched = schedFact.GetScheduler();
        sched.Start();
         
        // create job
        IJobDetail job = JobBuilder.Create<SimpleJob>()
                .WithIdentity("job1", "group1")
                .Build();
         
        // create trigger
        ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("trigger1", "group1")
            .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever())
            .Build();
         
        // Schedule the job using the job and trigger 
        sched.ScheduleJob(job, trigger);
         
        }
    }
     
    /// <summary>
    /// SimpleJOb is just a class that implements IJOB interface. It implements just one method, Execute method
    /// </summary>
    public class SimpleJob : IJob
    {
        void IJob.Execute(IJobExecutionContext context)
        {
        //throw new NotImplementedException();
        Console.WriteLine("Hello, JOb executed");
        }
    }
} 

Sources

  • Original url
like image 184
Bjørn Otto Vasbotten Avatar answered Sep 19 '22 18:09

Bjørn Otto Vasbotten