Tuesday, October 16, 2007

Custom Timer Job

I have been working on a Custom Timer Job (CTJ) to fix a little bug within our brand new intern portal. I have several tips for those who are making or willing to make one:

If you don't know how to make a CTJ? Take a look at: Example of a Custom Timer Job

How to debug a Custom Timer Job?

After installing and activating the CTJ - Feature
(Make sure that the code in the execute() method runs every minute. It takes less time to debug)

- Set a breakpoint somewhere in your code.
- Click 'Debug' in the toolbar (Visual Studio 2005)
- Click 'Attach to process'
- Select 'OWSTimer.exe'
- Everytime the code is being executed, the debugger starts working.
- Now you can enjoy 'debugging'


How to access the web.config within a Custom Timer Job?

Configuration config =
WebConfigurationManager.OpenWebConfiguration("/", "Sharepoint - 80");
string value = config.AppSettings.Settings["keyName"].value;

Hope , these tips save some developer time :)

No comments: