我有两种操作方法DayStart()
和DayEnd()
,我必须致电DayStart()
上午8:05(周一至周五)和DayEnd()
上午8:04(周一至周五)这是迄今为止Quartz.net的最佳选择,但我不知道如何打电话jobExecution方法中的这两个动作方法。
有没有办法实现这个目标?
public ActionResult StartDay()
{
int userid = Auth.UserID;
daysServices.StartDay(userid);
return RedirectToAction("Index", "Home", new { isdayClose = false });
}
public ActionResult CloseDay()
{
int userid = Auth.UserID;
int dayId = daysServices.getActiveDay();
int shiftId = daysServices.getActiveShift();
daysServices.CLoseDay(dayId, userid, shiftId);
return RedirectToAction("TokenDayAmount", "Home", new { isdayClose = true });
}
public async Task Execute(IJobExecutionContext context)
{
await Console.Out.WriteLineAsync("HelloJob is executing.");
//I hope something like this? DayStart();
}
答案 0 :(得分:1)
您需要三个步骤。首先创建一份工作
public class SomeJob : IJob
{
public void Execute(IJobExecutionContext context)
{
DayStart(); //this is your start method
}
}
其次,当您的工作执行时,您需要一个调度程序。您可以使用Cron Trigger
安排工作,如
public class SomeJobScheduler
{
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<SomeJob>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithCronSchedule("0 05 8 ? * MON-FRI *") //This expression to schedule your job Mon-Fri 8.05 AM
.Build();
scheduler.ScheduleJob(job, trigger);
}
}
您可以找到有关Cron Ttrigger
Here
第三次致电Scheduler
中的Global,asax.cs
。
void Application_Start(object sender, EventArgs e)
{
SomeJobScheduler.Start();
}