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.

[sourcecode language=”csharp”]
using System;
using Quartz;

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

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

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

[sourcecode language=”csharp”]
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);
}
}
}
[/sourcecode]

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

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

  1. Pingback: DotNetShoutout

Comments are closed.