Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I built a custom Timer Job on activation I was able to debug it and it was going through Execute method I am overriding but suddenly its not overriding anymore.

Code is here:

   public class TimerJob : SPJobDefinition
    {
        private const string TIMERJOB_NAME = "Timer Job";

        public TimerJob()
            : base()
        { 
        }

        public TimerJob(SPWebApplication webApp)
            : base(TIMERJOB_NAME, webApp, null, SPJobLockType.ContentDatabase)
        { 
            this.Title = TIMERJOB_NAME; 
        }

        public override void Execute(Guid targetInstanceId)
        {
            try
            {
                //System.Diagnostics.Debug.Assert(false);
                getPendingItems();
            }
            catch (Exception ex)
            {
                AppCode.Logging.LogWepApplicationErrorMessage(ex, TIMERJOB_NAME, this.WebApplication.Name);
            }
        }

While Debugging it goes through second constructor and ignores Execute method and returns control to Feature Receiver class

Edited

I defined schedule as below, but even after 5 minutes when I check Job properties > Last run time: it says N/A

    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 120;
    //SPHourlySchedule schedule = new SPHourlySchedule();
    //schedule.BeginMinute = 0;
    //schedule.EndMinute = 3;
    TimerJob.Schedule = schedule;
    TimerJob.Update();

simply doesn't work :(

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Unless you're explicitly calling Execute from within your FeatureReceiver then it should't be called at that time.

The Execute method should be called by the timer service when it's running your timer job

Specifying an EndSecond of 120 isn't valid BeginSecond and EndSecond specify where in the minute it should start and no minutes have more that 60 seconds.

And you don't specify how often it should run by setting Interval.

What you meant was probably:

SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 2;
TimerJob.Schedule = schedule;  
TimerJob.Update();  

This specifies run every second minute (anywhere in that minute)

And also remember to recycle the TimerJob Service whenever you update your timerjob.

share|improve this answer
    
I edited my question –  Muhammad Raja Jul 27 '12 at 11:03
    
true, I am not calling it anywhere it should be called automatically :) –  Muhammad Raja Jul 27 '12 at 11:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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