Service & Scheduler: Using Topshelf, Quartz, & Other OSS Bits Part 2

In the previous entry in this series I setup a service using TopShelf.┬áNow it is time to jump into scheduling with Quartz. I’ve started an entirely new service to work through an example of this service functionality.

To read more about Quartz.NET from the source, check out the Quartz.NET Project Site or the Github Repo.

Open up Visual Studio and create another Windows Console Project. Next add a reference to Quartz.NET with Nuget.

Adding Quartz.

Adding Quartz.

Next add a class called SomeJob as shown.

using System;
using Quartz;

namespace quartz
{
    public class SomeJob : IJob
    {
        public SomeJob() { }

        public void Execute(JobExecutionContext context)
        {
            Console.WriteLine("DumbJob is executing.");
        }
    }
}

Next add and change the code in Program.cs to the code below.

using System;
using Quartz;
using Quartz.Impl;

namespace quartz
{
    class Program
    {
        static void Main()
        {
            var schedFact = new StdSchedulerFactory();

            var sched = schedFact.GetScheduler();
            sched.Start();

            var jobDetail =
                new JobDetail("myJob", null, typeof(SomeJob));

            var trigger = TriggerUtils.MakeSecondlyTrigger(5);
            trigger.StartTimeUtc = DateTime.UtcNow;
            trigger.Name = "myTrigger";
            sched.ScheduleJob(jobDetail, trigger);
        }
    }
}

NOTES: Working code available on Github under my Quartz Repo.

2 thoughts on “Service & Scheduler: Using Topshelf, Quartz, & Other OSS Bits Part 2

  1. DotNetShoutout

  2. Service & Scheduler: Using Topshelf, Quartz, &... | .NET and Architecture | Syngu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s