0

我必须在隔天使用自定义计时器作业执行一些操作吗? 下面创建和启动计时器作业(在功能接收器中)的代码,但它每天运行,我必须隔天运行它

怎么做?

private bool CreateJob(SPSite site) { 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;
    }
4

1 回答 1

1

I think the code above run every 15 minute, you have SPMinuteSchedule, you must use SPDailySchedule. See msdn documentation

However when Job run you can get the current DayOfWeek and run your code when you want

        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;
        }

Or you can save inside Job Property Bag the last run. At this link you can find an example for SPWeb but is the same for SPJob.

于 2014-10-21T08:49:57.290 回答