1

I have vs 2010, moss 2010, and I'm trying to debug a custom timer job, so I've set breakpoints on the feature receiver, but when I run the project or just right click deploy, my break points are never met.

Here is the code, as you can see its just a standard feature receiver:

public class StructureImportEventReceiver : SPFeatureReceiver
{
    const string List_JOB_NAME = "StructureImporter";

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;
        // Break point is set on line above ... rest of code below
    }
}

I guess if I could get the debugger to stop on this breakpoint, I could step through to the rest of the timer job, but alas... nothing. What am I doing wrong?

6 Answers 6

1

There was a well-known technique to debug a custom timer job on MSDN: http://msdn.microsoft.com/en-us/library/cc406686.aspx#WSSCustomTimerJobs_DebuggingCustomTimerJobs

The technique should be still valid in SharePoint 2010. Also check out: http://www.codeproject.com/KB/sharepoint/debugging-sharepointjobs.aspx

1
  • Instead of System.Diagnostics.Trace.Assert(false), you can use System.Diagnostics.Debugger.Break(). This will directly provides a debug engine choose dialog.
    – Steve B
    Commented Jun 8, 2012 at 14:44
6

You need to attach to OWSTIMER process instead of w3wp to debug timer jobs. Don't forget to restart the service after deploying latest code to debug.

1

Here is what I generally use:

  1. From VS2010, I do an F5 to deploy and debug the solution. Also I manually attach the owstimer.exe with executing code. Note: If this does not work, then you should try restarting the SharePoint timer service.

  2. Another ways is to manually put the .pdb file inside the solution assembly folder under GAC (C:\Windows\assembly\gac_msil) and do a IIS reset. Further attach the owstimer.exe with the VS2010 solution and wait for the timer to hit the code.

1

Call System.Diagnostics.Debugger.Launch() to debug your timer job. Place this line of code in your Execute method on the Timer Job itself.

1
  • While this post may answer the question, we prefer more details such as "why". Please edit your post with additional details. See answer for general guidelines. (Short answers like this get flagged by the system.) Thanks.
    – SPDoctor
    Commented Jun 6, 2012 at 7:40
1

For sharepoint 2007 or sharepoint 2010 you can attach OWSTimer.exe. If still it does not work then restart the timerjob service in services.msc

Please visit my article http://sharepoint.infoyen.com/2012/06/16/custom-timer-job-in-sharepoint/

to know about

   Create Custom timer job
   debug timer job
   deploy timer job
   using WSP and feature deploy timer job
   Use TimerJobdefinition class
   pass & store url timer job property bag
   restarting timer job
0

Follow below steps to debug Timer Job:

  1. Put break point from where you want to start debug.

  2. From Debug menu select >> Attach to process

  3. Select OWSTIMER.exe and click on Attach button.

  4. Deploy project and wait until execution stops at break point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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