RSS Feed Feed your read!

Scot Hillier is an independent consultant and Microsoft SharePoint Most Valuable Professional focused on creating solutions for Information Workers with SharePoint, Office, and related .NET technologies. A frequent speaker at TechEd and SharePoint Connections, he is also the author many books on Microsoft technologies including 5 for SharePoint 2010. Scot splits his time between consulting on SharePoint projects and training for Critical Path Training. Scot is a former U. S. Navy submarine officer and graduate of the Virginia Military Institute. Scot can be reached at scot@shillier.com

Archives

January 2010 (17)
February 2010 (1)
March 2010 (1)
April 2010 (2)
May 2010 (1)
June 2010 (1)
August 2010 (4)
September 2010 (6)
October 2010 (3)
November 2010 (2)
February 2011 (1)
March 2011 (4)
April 2011 (3)
May 2011 (1)
August 2011 (1)
March 2012 (1)
April 2012 (1)
July 2012 (3)
August 2012 (1)
September 2012 (1)
October 2012 (2)
November 2012 (3)
January 2013 (2)
February 2013 (3)
March 2013 (3)
April 2013 (3)
May 2013 (1)
September 2013 (2)
November 2013 (5)
January 2014 (2)
February 2014 (2)
March 2014 (1)
April 2014 (1)
May 2014 (1)
July 2014 (1)

Links

IT Unity
SharePoint Team Blog
Andrew Connell's Blog

Tag Cloud

Apps, Books, Business Data Connectivity, Claims, Conferences, JavaScript, jQuery, MOSS 2007 Archived Post, PowerShell, REST and CSOM, Search, SharePoint 2010, SharePoint 2013, Web Content Management,

SharePoint 2010 Timer Job Item 

Tags:

I finally completed a project I have wanted to do for a while, which was to create a project template for SharePoint 2010 timer jobs. The SharePoint 2010 Timer Job Item appears in the Add Item dialog when creating SharePoint 2010 solutions in Visual Studio 2010. After you download and install the extension, you can follow this walkthrough to get started. Additional information is available at the end of the walkthrough.

Update (4/13/2011): Found a small error in the AppData class. A new version 1.1 is posted for download.

Walkthrough

1. Open Visual Studio 2010 and select File>>New>>Project

2. In the New Project dialog, select to create an Empty SharePoint Project.

3. Make sure to create a Farm Solution when prompted and use the URL for Central Administration as the target.

4. In the Solution Explorer, right click the project and select Add New Item from the context menu.

5. In the New Item dialog, select to add a new Timer Job and name it HelloJob.

6. When the item is added, you will be prompted to provide a name for the Timer Job. Name it Hello.

7. At this point, the project already has simple logging code written into the Worker.cs class, so you can right-click the project and select Deploy from the context menu. At the end of the walkthrough, I'll discuss the advanced capabilities of the Timer Job item.

8. If you deploy from Visual Studio 2010, the feature will be activated on every Web Application in your farm except Central Administration, which is not exactly what you want. Go to the Manage Web Applications page and deactivate the feature manually for all the Web Applications. Then activate it for the Central Administration Web Application.

9. Once the feature is activated, go to Central Administration>>Monitoring. You will see a link to manage the new timer job.

10. Click the link and you will see the management page where you can set the schedule for the job. Select Immediate.

11. Give the job a few minutes to run and then open the ULS Logs. You should see the job has written entries to the logs.

 

Advanced Capabilities

The Timer Job item was written to provide capabilities that are commonly required. The most important of these capabilities is the ability to manage configuration data like connection strings. When creating timer jobs, you can store the configuration data in several places such as the config file for OWSTIMER or a custom file in your feature. The Timer Job item uses the hierarchical object store to manage configuration values.

 

Managing the configuration values is accomplished through the AppData class. If you examine the class, you will see that it is set up to track the schedule that is selected in the timer job management page. However, you can add your own configuration values to the class.

 

Setting configuration values for the timer job is done in the timer job management page ManageJob.aspx. Initially, this page only allows you to select the schedule; however, you can easily add custom code to include a place for adding other configuration values. These values can then be saved using the AppData class.

 

The Timer Job item also provides a custom logging class named Logger. This class provides a LogInfo and LogError clas that you can use to trace the progress of the timer job. You can easily add additional methods for more control over the logging.

 
Posted by Scot Hillier on 13-Apr-11
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Links to this post

Comments