Quartz.net に関する大きなプロジェクトがあります。私はいくつかのタスクを作成するためにいくつかのジョブを作成しました。そこで、私を理解するための要約プロジェクトを作成しました。仕事があります。いくつかの値をジョブのプロパティに解析したいと考えています。実行時に、ジョブはこれらのプロパティを必要とします。しかし、私はそれを行うことはできません。「なぜ 'JobDetail.JobDataMap' を使用しないのですか?」と言わないでください。私は以下の構造が必要です:
JobBase を見てください:
public abstract class JobBase : MarshalByRefObject, IStatefulJob
{
void IJob.Execute(JobExecutionContext context)
{
this.Execute();
}
protected abstract void Execute();
}
また、Test.cs (それは私の仕事です!)
Test.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);
}
}
}
My Project 開始スケジュール :
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);