Timer Job not getting deployed in Sharepoint 2013

Hi,

I am creating a Timer Job in Sharepoint 2013 using the below mentioned links:

 - http://www.splessons.com/2013/12/create-a-timer-job-in-sharepoint-2013/
 - http://www.codeproject.com/Tips/634208/Create-and-Deploy-Custom-Timer-Job-Definition-in-S

My solution is getting deployed and I can activate/deactivate feature from Central Admin. But the timer job is not appearing in CA.

When I attached the debugger at the Timer Job's class file, it gets goes only to the first constructor. i.e. at the non parameterized constructor.
The debugger does not go to the other 2 constructors.
Moreover, when I try to debug the Feature's event receiver the debugger does not stops at the code, it only stops at the Timer Job's class file.

I am doing it with all the administrator rights.

Any help!!

My Event Receiver Code is :

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SharePointProj4.Features.Feature1
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("6f5a5ed1-98d3-4cde-a497-deef1b3b1467")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.
        const string JobName = "SP Task Timer";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWebApplication parentWebApp = (SPWebApplication)properties.Feature.Parent;
                    SPSite site = properties.Feature.Parent as SPSite;
                    DeleteExistingJob(JobName, parentWebApp);
                    CreateJob(parentWebApp);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            lock (this)
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        SPWebApplication parentWebApp = (SPWebApplication)properties.Feature.Parent;
                        DeleteExistingJob(JobName, parentWebApp);
                    });
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }


        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;
            try
            {
                SPJobs.SPTImerJobClass job = new SPJobs.SPTImerJobClass(JobName, site, "http://win-njfp7te48bn/");
                //SPJobs.SPTImerJobClass job = new SPJobs.SPTImerJobClass(JobName, site);
                SPMinuteSchedule schedule = new SPMinuteSchedule();
                schedule.BeginSecond = 0;
                schedule.EndSecond = 59;
                schedule.Interval = 15;
                job.Schedule = schedule;

                job.Update();
            }
            catch (Exception)
            {
                return jobCreated;
            }
            return jobCreated;
        }
        public bool DeleteExistingJob(string jobName, SPWebApplication site)
        {
            bool jobDeleted = false;
            try
            {
                foreach (SPJobDefinition job in site.JobDefinitions)
                {
                    if (job.Name == jobName)
                    {
                        job.Delete();
                        jobDeleted = true;
                    }
                }
            }
            catch (Exception)
            {
                return jobDeleted;
            }
            return jobDeleted;
        }

        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}


and my TimerJob Code is :

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

namespace SharePointProj4.SPJobs
{
    class SPTImerJobClass : SPJobDefinition
    {
        public SPTImerJobClass() : base() { }

        public SPTImerJobClass(string jobName, SPService service) : base(jobName, service, null, SPJobLockType.None)
        {
            this.Title = jobName;
        }

        public SPTImerJobClass(string jobName, SPWebApplication webapp) : base(jobName, webapp, null, SPJobLockType.ContentDatabase)
        {
            this.Title = jobName;
        }

        public override void Execute(Guid targetInstanceId)
        {
            SPWebApplication webapp = this.Parent as SPWebApplication;
            SPList tasklist = webapp.Sites[0].RootWeb.Lists["Tasks1"];
            SPListItem newTask = tasklist.Items.Add();
            newTask["Title"] = "New Task" + DateTime.Now.ToString();
            newTask.Update();
        }
    }
}

September 7th, 2015 6:37am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics