问题
I am writing a timer job for the first time. I am following the examples that can be obtained by googling as my reference.
In many such articles, I am coming across the timer job features being activated to the Site Collection level or the Site level.
I feel this is weird, since there can be only one instance of a timer job for a particular web application.
Should't all the timer job features be scoped to a Web application?
Am I missing anything here?
回答1:
It depends entirely on your scenario. The timer jobs I've written so far I have scoped by web application (it's just a matter of modifying your feature.xml). However, depending on what your timer job does, it might make sense from a user perspective to have it web or site scoped. You'd only need to make your feature receiver aware of the 'parent' that's passed in the Activated etc. notification handlers -- it will be the SPWeb, SPSite or SPWebApplication that the feature was activated on -- and you could save yourself writing a configuration interface just to have users set which webs your timer job should work with, and which not. Technically you're correct: they always run on the web application level. But since they often work with content that's web or site related, scoping this way might be a useful way to limit the, well, scope of the timer job.
来源:https://stackoverflow.com/questions/792938/scope-of-a-timer-job-feature