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 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?

share|improve this question
add comment

5 Answers

up vote 0 down vote accepted

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

share|improve this answer
    
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 Jun 8 '12 at 14:44
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
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 Jun 6 '12 at 7:40
add comment

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
share|improve this answer
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.