1. Create empty SharePoint project
2. Create class inherits from the Microsoft.SharePoint.Administration.SPJobDefinition
3. To implement this class, you need to create a few constructors and override the Execute() method as following
4. Right click on the Features >Add Feature
5. Right click on the Feature1 ” you can rename the Feature1 to any name” > Add Event Receiver
6. But we need FeatureActivated & FeatureDeactivated event handler to install/uninstall our custom timer job .
7.Before Deploying you should select the right scope of the Feature in other words in which scope you will activate the Feature(Farm,Site,Web,WebApplication) in our case we will activate Feature1 on Site which is mean Central Site Collection.
8. Take care that SPContext is not used anywhere in this project. Before deploying,
10. Now let us deploy our custom timer job >Right Click on Custom_TimerJob project > Click Deploy
11. Open now your SharePoint site -in job timer we will see our deployed job.
12. if deploy succeeded We should be able to see timer job in central site under job definitions.
13. set this timer job for specific time now.
How to Debug Timer job if problem occurs –
As scheduler is set to specific time for application to run, we can debug it when it runs
Debugging In Visual Studio
Set a breakpoint in your timer job code, and then open the "Attach to Process" dialog from the Debug menu. Check the box at the bottom of the dialog titled "Show Processes from All User", and select OWSTIMER.EXE from the list of available processes. Click the Attach button.....Now click Debug to run application.
Set a breakpoint in your timer job code, and then open the "Attach to Process" dialog from the Debug menu. Check the box at the bottom of the dialog titled "Show Processes from All User", and select OWSTIMER.EXE from the list of available processes. Click the Attach button.....Now click Debug to run application.
Triggering the Job
Now you just need to trigger your timer job. One suggestion for this is to modify the schedule of the job to occur frequently
Now you just need to trigger your timer job. One suggestion for this is to modify the schedule of the job to occur frequently
No comments:
Post a Comment