views:

2645

answers:

2

Hai Guys, I dont 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...

+18  A: 

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

TskTsk
Nice work! Got it running in 3 minutes. Works quite well.
RKitson
A: 

Unable to connect to the remote server

I used your code, but get the error message below: "Unable to connect to the remote server" and in view detail "No connection could be made because the target machine actively refused it 172.22.22.17:555" . I even tried to pass the registry host and port in the server application by adding:

properties.Add("quartz.scheduler.rmi.registryHost", "localhost");
properties.Add("quartz.scheduler.rmi.registryPort", "555");

Any help is appreciated

elham
create another question and delete this answer
Mauricio Scheffer