1

I am trying to implement a custom timer job in my SP 2013 on-premises appln. I have created the same. But the timer job is not appearing in the timer job definitions page.

I have activated and deactivated the feature multiple times, and after doing multiple IISRESET and sptimer services restarts, and sp admin service restarts , the timer job failed to visible.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Administration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint; 

  namespace RILTILPTimerJob.RILTTimerJob
     {
  public  class FreezeDocTimerJob  :SPJobDefinition
   {
    HashSet<string> seenUids = new HashSet<string>(); 

    public const string JobName = "FreezeDocument Timer Job"; 
    public FreezeDocTimerJob() : base() { }
    public FreezeDocTimerJob(string jobName, SPService service, SPServer 
    server,SPJobLockType targetType) : 
      base(jobName, service, server, targetType)
        {   }

      public FreezeDocTimerJob(string jobName, SPWebApplication webapp, 
       string strUrl) : 
      base(jobName, webapp, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "FreezeDocument Timer Job";
        }

  /// <summary>
  /// execute method of rilt timer job
  /// </summary>
  /// <param name="ContentDatabaseID"></param>
       public override void Execute(Guid ContentDatabaseID) 
       {  
           try   
           {
               SPWebApplication webApp = this.Parent as SPWebApplication;
               SPList objlistRILTList = webApp.Sites
         [0].RootWeb.Lists.TryGetList("RILTLIST");
               SPListItem objRILTTaskItem = objlistRILTList.Items.Add();
               objRILTTaskItem["Title"] = "New_Task_RILTWFTIMER_" + 
      DateTime.Now.ToString();
               objRILTTaskItem.Update();
            }   
           catch (Exception expinXecute_RILTTimerJob)  
           {    
             }  
         }   
        }  
       }
1

Please go through your Feature Event Receiver code again that is creating a custom timer job on "FeatureActivated" event. Before writing code for creating a timer job, delete the timer job if it is already existing and then create the custom timer job.

Also assign the title of timer job inside below method:

public FreezeDocTimerJob(string jobName, SPService service, SPServer 
    server,SPJobLockType targetType) : 
      base(jobName, service, server, targetType)
        {  
            this.Title = "FreezeDocument Timer Job";
        }
0

Your code looks good. You have to specify that the scope of the Feature should be "Site" in visual studio for SharePoint 2013 that is how timer job creating.

enter image description here

  • I think , scope of the timer job must be WEB APPLICATION. and NOT site collection. am working in SP 2013 ON-PREM. can you pls elaborate why SiteCollection will work – userAZLogicApps Apr 19 '17 at 12:05
  • not sure I have got same issue and referred some post previously and found this solution and it works well for me. – Suresh Bolineni Apr 19 '17 at 12:11

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.