Quartz can’t fire Job from XML Setting
Is my xml file correct? How can I fire Job from XML Setting?
My Quartz.Net sample finds the XML file but can’t fire Job, I have all the code below, can someone help please.
XMLFile1 file is inside bin folder and it is being read by ConfigXML.cs below.
Thanks in advance.
My class library consists of the following items:
My class Library is called MySample
- IExample
- ConfigXML.cs
- MyJob.cs
My Window Application consists of the following items:
My window application is called MyWindowSample.
- Form1
- XMLFile1: I put this file in my bin folder.
IExample Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
namespace MySample
{
public interface IExample
{
string Name
{
get;
}
void Run();
}
}
Here is the ConfigXML Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using System.Collections.Specialized;
using System.Threading;
using Common.Logging;
using Quartz.Impl;
using Quartz.Impl.Calendar;
namespace MySample
{
public class ConfigXML: IExample
{
public string Name
{
get { throw new NotImplementedException(); }
}
public void Run()
{
ILog log = LogManager.GetLogger(typeof(ConfigXML));
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "XmlConfiguredInstance";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.plugin.xml.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz";
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
properties["quartz.plugin.xml.fileNames"] = path + @"\XMLFile1.xml";
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
sched.Start();
try
{
Thread.Sleep(30 * 1000);
}
catch (ThreadInterruptedException)
{
}
sched.Shutdown(true);
}
}
}
Here is MyJob code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
namespace MySample
{
class MyJob: IJob
{
public void Execute(IJobExecutionContext context)
{
string str = "This is MyJob Testing";
}
}
}
MySampleWinodw Application – Form1.cs code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySample;
namespace MySampleWindow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
MySample.ConfigXML xmlConfigurationExample;
xmlConfigurationExample = new MySample.ConfigXML();
xmlConfigurationExample.Run();
}
}
}
XMLFile1 code:This file is inside bin folder and it is being read.
<?xml version="1.0" encoding="UTF-8"?>
<quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
overwrite-existing-jobs="true">
<job>
<job-detail>
<name>MyJob</name>
<group>MyJobs</group>
<description>Logs a message to the application log</description>
<job-type>MySample.MyJob, MySample</job-type>
<volatile>false</volatile>
<durable>true</durable>
<recover>false</recover>
<job-data-map>
<entry>
<key>MessageToLog</key>
<value>Hello from MyJob</value>
</entry>
</job-data-map>
</job-detail>
<trigger>
<cron>
<name>MyJobTrigger</name>
<group>MyJobs</group>
<description>A description</description>
<job-name>MyJob</job-name>
<job-group>MyJobs</job-group>
<cron-expression>0/20 * * * * ?</cron-expression>
</cron>
</trigger>
</job>
</quartz>