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 want to create a timer job that will be on all of SharePoint's web applications.

It's not a problem - but I'm thinking of the situation when a new web application is created.

Will my timer job be automatically provisioned on that web application as well?

If not, How can I create a timer job that does?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

It's all about in the way you construct your Feature receiver. Simply create a Web Application scoped feature, which is automatically activated (set this in VS already in the Properties window). In this you would put something like that:

SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

//Add code to check whether it is already added and Remove it 1st.
DeleteJob(webApp.JobDefinitions);

MyJobDefinition myJob = new MyJobDefinition(webApp);

//set schedule and other properties and then run Update 
myJob.Update();

Which constructor you choose is important, because beyond the WebApplication you would also have to consider "where" (on which server it runs - Central Admin by default, or specifically Front Ends..etc., i believe this examples would help http://www.martinhatch.com/2009/08/sharepoint-timer-jobs-and-multiple.html).

Not sure if you've gone through this article, as a comprehensive guide http://www.simple-talk.com/dotnet/.net-tools/a-complete-guide-to-writing-timer-jobs-in-sharepoint-2010/

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.