0

I'm writing a custom timer job in C# and need to pick a service to associate my timer job with. I've tried the local timer service:

: base(String.Format(JOB_NAME, Guid.NewGuid()), SPFarm.Local.TimerService, server, SPJobLockType.None)

This has been pretty spotty, we've had issues getting this job to run reliably enough on all servers in a farm to be satisfied with. We think this is due to the timer service not updating with the new job sometimes -- clearing the SharePoint config cache and forcing the timer service to update has "fixed" the issue, but we obviously can't use that as a final solution to the issue.

What other services could I possibly associate this job with? I don't want to associate with a web app instead.

  • Hi are you wanting the job to run on all servers or just run and you don't mind which server its running on? – Simon Doy Jul 30 '13 at 14:30
1

I'll presume that you want it to run on all servers.

How about using the following class, Microsoft.SharePoint.Administration.SPServiceJobDefinition.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spservicejobdefinition.aspx

If you continue to use SPFarm.Local.TimerService SPService object, as this service is running on all SharePoint servers this will run the job on all servers.

I have been using this for a while and it seems to work fine.

To answer the question, you can associate to any object that inherits from the SPService class.

As for selecting an SPService, will that depends what you need it to do. For example you could associate to a Service Application if you wish. The timer job would only execute on the servers that are running the Service Application's Service Instance.

  • Interesting -- this doesn't really address the question, but I'll switch my class inheritance and constructor to this and see what happens. I do indeed want to run it on all servers. – tnw Jul 30 '13 at 15:13
  • I think you do want to associate it with the Timer Service so that it runs on all servers. However, I have updated the answer to include a further example of a service. – Simon Doy Jul 30 '13 at 15:19
  • It's kinda an odd scenario... it's a timer job that runs on all servers and actually provisions a service on that server. I'll let you know if it works. – tnw Jul 30 '13 at 15:31
  • Ah ok - sounds interesting. Is it provisioning a service application or something else like a windows service? Another approach would be using PowerShell. I found this article useful when I was doing Service Applications, danlarson.com/page/2 – Simon Doy Jul 30 '13 at 19:08
  • This did not work as I'm running into the same caching issue with the timer service. This is a cool feature though... I need to find a specific service to associate this job with that I know will be running on any server I want to install my service on. The Timer Service is perfect for this, I dont know what else to use! – tnw Jul 30 '13 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.