我有一个关于 Quartz.net 的大项目。我已经创建了一些工作来完成一些任务。所以我做了一个总结项目来了解我。我有工作。我想将一些值解析为工作的属性。在执行时,作业需要这些属性。但我不能那样做。请不要说“为什么不使用'JobDetail.JobDataMap'?” 我需要以下结构:
查看 JobBase:
public abstract class JobBase : MarshalByRefObject, IStatefulJob
{
void IJob.Execute(JobExecutionContext context)
{
this.Execute();
}
protected abstract void Execute();
}
还有Test.cs(这是我的工作!)
测试.cs:
public class Test : JobBase
{
public string FileName { get; set; }
public string Ip { get; set; }
protected override void Execute()
{
Ping ping = new Ping();
PingReply pingReply = ping.Send(Ip);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(FileName, true))
{
file.WriteLine(pingReply.Address);
}
}
}
我的项目开始时间表:
private void btnProperties_Click(object sender, EventArgs e)
{
ISchedulerFactory schedfabrikayeni;
IScheduler schedyeni;
JobDetail job;
CronTrigger trigeryeni;
NameValueCollection properties = new NameValueCollection();
properties["FileName"] = @"C:\temp\pingresult.txt";
properties["Ip"] = "192.168.16.14";
schedfabrikayeni = new StdSchedulerFactory(properties);
schedyeni = schedfabrikayeni.GetScheduler();
job = new JobDetail("myJob", null, typeof(Test));
JobDataMap map = new JobDataMap();
map.Put("msg", "Your remotely added job has executed!");
job.JobDataMap = map;
string cronExpressiontxt = string.Empty;
//0 0 12 1 4 ? *
cronExpressiontxt = "0 0/1 * 1/1 * ? *";
trigeryeni = new CronTrigger("triger1", null, "myJob", null, cronExpressiontxt);
schedyeni.ScheduleJob(job, trigeryeni);
schedyeni.Start();
}
但我的 Ip 为 null 我的 FileName 为 null。如何使用以下用法设置属性:
NameValueCollection properties = new NameValueCollection();
properties["FileName"] = @"C:\temp\pingresult.txt";
properties["Ip"] = "192.168.16.14";
schedfabrikayeni = new StdSchedulerFactory(properties);