Reputation: 466
I have a solution with a single winforms project targeting .Net 2.0. I need some of the quartz functionality in of the project's forms but I cannot add the package since it requires higher version of .Net. Is there any workaround in this situation? Edit: maybe there is another scheduling tool for .Net 2.0? I only need the feature that executes required method at required time.
Upvotes: 1
Views: 773
Reputation: 125197
You can use Quartz 1.0 using .NET Framework 2.0. Quartz versions starting 2.0 doesn't work with .NET Framework 2.0 and rely on some features of .NET 3.5 and upper versions rely on .Net 4.0.
To use Quartz with a .NET 2.0 Project:
Quartz 1.0
(or 1.0.1 or 1.0.2 or 1.0.3) bin\2.0\Release\Quartz
path, add reference to Quartz.dll
and Common.Logging.dll
. using System;
using System.ComponentModel;
using System.Windows.Forms;
using Quartz;
using Quartz.Impl;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1() { InitializeComponent(); }
IScheduler scheduler;
protected override void OnLoad(EventArgs e)
{
ISchedulerFactory schedFact = new StdSchedulerFactory();
scheduler = schedFact.GetScheduler();
scheduler.Start();
JobDetail jobDetail = new JobDetail("SampleJob", null, typeof(SampleJob));
Trigger trigger = TriggerUtils.MakeSecondlyTrigger(5); //Run every 5 seconds
trigger.StartTimeUtc = DateTime.UtcNow;
trigger.Name = "SampleJobTrigger";
scheduler.ScheduleJob(jobDetail, trigger);
base.OnLoad(e);
}
protected override void OnClosing(CancelEventArgs e)
{
scheduler.Shutdown(false);
base.OnClosing(e);
}
}
public class SampleJob : IJob
{
public SampleJob() { }
public void Execute(JobExecutionContext context)
{
MessageBox.Show("DumbJob is executing.");
}
}
}
To learn more about Quartz:
Upvotes: 1