Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Quartz.net with ASP.NET

I don't know how to use Quartz.dll in ASP.NET. Where to write the code for scheduling jobs to trigger mail every morning? Please if some body knows about it plz help me...

Edit: I found HOW TO use Quartz.NET in PRO way? to be really useful.

like image 384
ACP Avatar asked Aug 31 '09 10:08

ACP


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.

What is Quartz in asp net core?

Quartz.NET provides lots of scheduling features and has an easy to use API for implementing scheduled jobs. Code: https://github.com/damienbod/AspNetCoreQuartz. A simple ASP.NET Core Razor Page web application is used to implement the scheduler and the SignalR messaging. The Quartz Nuget package and the Quartz.

What is Quartz job in C#?

What is QUARTZ? 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.


1 Answers

You have a couple of options, depending on what you want to do and how you want to set it up. For example, you can install a Quartz.Net server as a standalone windows serviceor you can also embed it inside your asp.net application.

If you want to run it embedded, then you can start the server from say your global.asax, like this (from the source code examples, example #12):

NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteServer";  // set thread pool info properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal";  ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler(); sched.Start(); 

If you run it as a service, you would connect remotely to it like this (from example #12):

NameValueCollection properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "RemoteClient";  // set thread pool info properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz"; properties["quartz.threadPool.threadCount"] = "5"; properties["quartz.threadPool.threadPriority"] = "Normal";  // set remoting expoter properties["quartz.scheduler.proxy"] = "true"; properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler"; // First we must get a reference to a scheduler ISchedulerFactory sf = new StdSchedulerFactory(properties); IScheduler sched = sf.GetScheduler(); 

Once you have a reference to the scheduler (be it via remoting or because you have an embedded instance) you can schedule jobs like this:

// define the job and ask it to run JobDetail job = new JobDetail("remotelyAddedJob", "default", typeof(SimpleJob)); JobDataMap map = new JobDataMap(); map.Put("msg", "Your remotely added job has executed!"); job.JobDataMap = map; CronTrigger trigger = new CronTrigger("remotelyAddedTrigger", "default", "remotelyAddedJob", "default", DateTime.UtcNow, null, "/5 * * ? * *"); // schedule the job sched.ScheduleJob(job, trigger); 

Here's a link to some posts I wrote for people getting started with Quartz.Net: http://jvilalta.blogspot.com/2009/03/getting-started-with-quartznet-part-1.html

like image 72
jvilalta Avatar answered Oct 07 '22 18:10

jvilalta