我的想法是建立一个Quartz.net任务:
我有这堂课:
public class Proccess
{
public static void Start()
{
Console.WriteLine("I'm starting");
}
public static void End()
{
Console.WriteLine("I'm finishing");
}
}
有没有办法配置Quartz.Net的作业来调用Process.Start()等待X分钟并调用Process.End()?
也许这样的事情?
public class TapWaterJob : IJob
{
public TapWaterJob()
{
// quartz requires a public empty constructor so that the
// scheduler can instantiate the class whenever it needs.
}
public void Execute(IJobExecutionContext context)
{
Proccess.Start();
System.Threading.Thread.Sleep(10000);
Process.End();
}
}
答案 0 :(得分:0)
如果你只是想要完成一些事情,似乎只是让对象停在它上面就是正确的方法(即为自己调用停止)。
如果你想让Quartz调用stop,你可以这样做:
var jobMap = new JobDataMap();
jobMap.Put("process", process);
var startJob = JobBuilder.Create<StartJob>()
.WithIdentity("startJob")
.SetJobData(jobMap).Build();
ITrigger startTrigger = TriggerBuilder.Create()
.WithIdentity("startTrigger")
.StartNow()
.Build();
var stopJob = JobBuilder.Create<StopJob>()
.WithIdentity("stopJob")
.SetJobData(jobMap).Build();
ITrigger stopTrigger = TriggerBuilder.Create()
.WithIdentity("stopTrigger")
.StartAt(DateTime.Now.AddMinutes(5))
.Build();
var sched = StdSchedulerFactory.GetDefaultScheduler();
sched.Start();
sched.ScheduleJob(startJob, startTrigger);
sched.ScheduleJob(stopJob, stopTrigger);
将5
参数替换为StartAt
,并使用一个您想要等待的分钟数的变量。