0

I have created a Web application scoped timer job in SharePoint 2013. This timer job is supposed to be running only once in a month , and should send an email only once . The problem i am facing is this job is running multiple times ,we have 2 WFE servers and it is running from both one by one. I checked several blogs and everyone says to put

(SPJobLockType.job) in the constructor :

  public TimerJob(string jobName, SPWebApplication webapp)
  : base(jobName, webapp, null, SPJobLockType.Job)

  {

            this.Title = "My Timer Job";

  }

which i have already done . the code is as below:

    class TimerJob : SPJobDefinition
    {
        public TimerJob()
            : base()
        {
        }

        public TimerJob(string jobName, SPService service)
            : base(jobName, service, null, SPJobLockType.Job)
        {
            this.Title = "My Timer Job";
        }

        public TimerJob(string jobName, SPWebApplication webapp)
            : base(jobName, webapp, null, SPJobLockType.Job)
        {
            this.Title = "My Timer Job";
        }

        public override void Execute(Guid targetInstanceId)
        {
            UpcomingNotifications.Run();  
        }
    }

Please suggest me something guys that this timer job should not run more than once.

  • Do you want the timer job to be executed only once in lifetime? Timer jobs basically runs on the give schedule. Hourly/Daily/Weekly/Monthly/Yearly like this. Please be specific what you are looking for. – Gaurravs Aug 18 '16 at 10:43
0

I guess you have missed to set the timer job schedule for your time like below

CustomTimerJob job = new CustomTimerJob(JobName, site);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 15;
job.Schedule = schedule;
job.Update();    

Job Schedules:

Minute Schedule

Daily Schedule

Monthly Schedule

To know more about SharePoint timer jobs, Click here.

  • i have done that , but when we set the time from central admin it runs only on that time ,doesnt it . – Revenant_01 Aug 18 '16 at 9:01
0

For Multiple Server Environment. Please follow these links.Stackoverflow reference, Martin Hatch Blog

If the above links helps, kindly mark this as answer. Thanks

0

actually I found out what I was doing wrong. When I was deploying this solution, I was deploying it on the central admin and the web application on which it should run,but for some reason it was getting deployed on all other web applications as well. I went to central admin->monitoring->Job definitions , and disabled the timer job from other web apps and only kept it enabled on the one I wanted it to run and it started working as I wanted i.e only once.

Hope it helps someone having the same issue .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.