public class IndexJob:IJob//此处必须实现 IJob接口
{
/// <summary>
/// 具体的任务
/// </summary>
/// <param name="context"></param>
IBLL.IkeyWordsRankService KeyWordService = new BLL.keyWordsRankService();
public void Execute(JobExecutionContext context)
{
KeyWordService.DeleteAll();
KeyWordService.InsertKeyWordRank();
}
}
static void Main(string[] args)
{
IScheduler iScheduler=new StdSchedulerFactory().GetScheduler(); //每隔一段时间执行任务 IScheduler sched;
ISchedulerFactory sf = new StdSchedulerFactory();
sched = sf.GetScheduler();
JobDetail job = new JobDetail("job1", "group1", typeof(IndexJob));//IndexJob为实现了IJob接口的类
DateTime ts = TriggerUtils.GetNextGivenSecondDate(null, );//5秒后开始第一次运行
TimeSpan interval = TimeSpan.FromSeconds();//每隔1小时执行一次
Trigger trigger = new SimpleTrigger("trigger1", "group1", "job1", "group1", ts, null,
SimpleTrigger.RepeatIndefinitely, interval);//每若干小时运行一次,小时间隔由appsettings中的IndexIntervalHour参数指定 sched.AddJob(job, true);
sched.ScheduleJob(trigger);
sched.Start();
Console.ReadKey();
//要关闭任务定时则需要sched.Shutdown(true)
}