Question

I have a little problem. I'm trying to add a timer job following this tutorial : http://dotnetfinder.wordpress.com/2010/07/24/creatingcustomsharepointtimerjob2010/

I came to the point where my timer job is enabled and is launching every five minutes. The problem is that it doesn't execute all the Execute method.

    public override void Execute(Guid contentDbId)
    {

        // get a reference to the current site collection's content database

        SPWebApplication webApplication = this.Parent as SPWebApplication;

        SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];

        // get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database

        SPList Listjob = contentDb.Sites[0].RootWeb.Lists["Liens"];

        // create a new list Item, set the Title to the current day/time, and update the item

        SPListItem newList = Listjob.Items.Add();

        //newList["URL"] = "http://"+DateTime.Now.ToString()+".fr";

        //newList.Update();

    }

I attached the debugger to the OWSTIMER.EXE. If i try to add a breakpoint at the line : SPList ListJob = ..., it's ok, But if i try to add a new breakpoint at the next line (SPListItem newList = ...) then i have the following message : "The following breakpoint cannot be set : ... The CLR was unable to set the breakpoint".

Does anyone has any idea how i can make it work ?

Was it helpful?

Solution

You seem to be attaching to the correct service. See How to: Debug a Timer Job to double check your steps.

Also, as pointed out in this comment, you should restart the timer service when deploying a timer job:

mark

February 11, 2011 at 4:41 am

There is a very important step that needs to be completed with any Timer Project. You hav to recycle the SharPoint timer service in between deployments. Best way to do this is to add

net stop SPTimerV4 – Pre Build

net start SPTimerV4 – Post Build

to your sharepoint project. If you do not do the above – you will be puzzled as to why your code seems not to be up to date. The reason is that the timer service Caches the assembly with your class. This can cost you hours of troubleshooting, in trying to identify why your code does not deploy.

OTHER TIPS

Make sure your project configuration is in Debug mode (in Release mode compiler is setting is enabled for optimized code). Refer to this blog post

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top