我必须在隔天?使用自定义计时器作业执行某些操作 代码创建和启动计时器作业(在功能接收器中),但它每天运行,我必须隔天运行?
怎么做?
private bool CreateJob(SPSite网站) { bool jobCreated = false; 尝试 {
TimerJob job = new TimerJob(JobName, site.WebApplication);
job.Title = JobName;
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 15;
job.Schedule = schedule;
job.Update();
}
catch (Exception)
{
return jobCreated;
}
return jobCreated;
}
答案 0 :(得分:1)
我认为上面的代码每 15分钟, SPMinuteSchedule ,您必须使用 SPDailySchedule 。见msdn documentation
但是,当Job运行时,您可以获得当前的DayOfWeek并在需要时运行代码
switch (DateTime.Now.DayOfWeek)
{
case DayOfWeek.Friday:
break;
case DayOfWeek.Monday:
break;
case DayOfWeek.Saturday:
break;
case DayOfWeek.Sunday:
break;
case DayOfWeek.Thursday:
break;
case DayOfWeek.Tuesday:
break;
case DayOfWeek.Wednesday:
break;
default:
break;
}
或者您可以在上次运行中保存作业 Property Bag 。 在this link,您可以找到SPWeb的示例,但对于SPJob也是如此。