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 comments
  1. Pingback: DotNetShoutout

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 )

Connecting to %s

Metal Cactus

Just another WordPress.com weblog

ChaniBlog

Code, cooking, and randomness.

plain old objects

the building blocks of software

midnight mystery ride

at midnight, we ride.

Riding on Roadways

Writing on Riding on Roadways

Not Rich Yet

It's going to happen. Gotta find something to do until then.

craftedincarhartt

Carhartt Women's Blog

heydev

For the love of code

Nathan Evans' Nemesis of the Moment

My nemesis of the moment

Open Source Bridge: Presentation Proposals

Snippets, software architecture, lean, agile, management, and leadership bits.

Captured Refractions

A collection of my latest adventures, past reflections and other photos.

for the love of Nike

for the love of Nike

The Cloud Dev

Developing {for/ on/ the} Cloud...

Project Manager in a Cloudy IT World

Thoughts, comments and ideas from experiences as a Project Manager in IT

iBikeuBike

If I can bike... So can you!

MAX FAQs

Portland Light Rail

UX Success

User Experience Design, Agile Development, Lean UX, Start Up

The lost outpost

a weblog by Andy Piper about technology, photography, and life

SaintGimp

Agile development, software craftsmanship, continuous improvement - Eric Lee's blog

Clang and Clamour

pardon the construction noises while we build the internet

Follow

Get every new post delivered to your Inbox.

Join 5,547 other followers

%d bloggers like this: