Tuesday, October 30, 2012

Debugging a Timer job

Hi Friends,

May be you are running with the time for creating Sharepoint timer job creation. You have started to create a feature with Event receivers, feature receivers and basic timer job class structure like below.

public class TimerJobClass : SPJobDefinition
{
      //Your contructors to handle different combinations of parameters
      public TimerJobClass()
     {
     }
    
     public TimerJobClass(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType)
     {
     }

     public TimerJobClass(string jobName, SPWebApplication webApplication, string targeturl)
            : base(jobName, webApplication, null, SPJobLockType.Job)
        {
            this.Title = "Timer Job Name";
        }
    
      public override void Execute(Guid contentDbId)
      {
            //Things need to do.
      }
}

After this structure declaring, you may be started with sample method designing and try to debug the timer job with below line

System.Diagnostics.Debugger.Break();

You may be wonder that you have copied the dll to GAC and did a IISRESET, and ran the sp timer job definition but the debugging engine of the VS 2010 never fires even after run the timer job.

I know your problem, Restart the "Sharepoint 2010 Timer" job  and then start the IISRESET. ....magic appears.....there you get the debugger fires upon the timer running.

Happy coding,

Buddike