| At the end the class would look like below. As said earlier this class will inherit from the Microsoft.SharePoint.SPFeatureReceiver class and implement the FeatureActivated & FeatureDeactivated event handlers: public class MySPTimerJobActivationFeatureReceiver : SPFeatureReceiver { public const string My_Timer_Job = "Notification Timer Job"; #region Feature Activated public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { ////Get the Site collection SPSite SiteCol = (SPSite)properties.Feature.Parent; SPWebApplication webApp = SiteCol.WebApplication; SPJobDefinitionCollection jobCol = webApp.JobDefinitions; ////Deleting older vrsion of Job if exists SPJobDefinition jobToDelete = null; ////Deleting the Job on deactivation of the feature foreach (SPJobDefinition objMyJob in jobCol) { if (objMyJob.Name == My_Timer_Job) jobToDelete = objMyJob; } if (jobToDelete != null) jobToDelete.Delete(); ////Install the Job Definition MySPTimerJobActivation oTimerJob = new MySPTimerJobActivation(My_Timer_Job, webApp, null, SPJobLockType..Job); ////Set the Site Url.. will be used later from the Timer Job Class oTimerJob.Properties["SiteURL"] = SiteCol.Url; ////Run the Scheduler every 2 minutes SPMinuteSchedule minSchedule = new SPMinuteSchedule(); minSchedule.BeginSecond = 0; minSchedule.EndSecond = 30; minSchedule.Interval = 2; oTimerJob.Schedule = minSchedule; oTimerJob.Update(); } catch (Exception ex) { Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception occured in fetch query module– {0} – {1}", ex.Message, ex.StackTrace); } } #endregion #region Feature Deactivating public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { try { SPSite SiteCol = (SPSite)properties.Feature.Parent; SPWebApplication webApp = SiteCol.WebApplication; SPJobDefinitionCollection jobCol = webApp.JobDefinitions; ////Deleting older vrsion of Job if exists SPJobDefinition jobToDelete = null; ////Deleting the Job on deactivation of the feature foreach (SPJobDefinition objMyJob in jobCol) { if (objMyJob.Name == My_Timer_Job) jobToDelete = objMyJob; } if (jobToDelete != null) jobToDelete.Delete(); } catch (Exception ex) { Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception occured in fetch query module– {0} – {1}", ex.Message, ex.StackTrace); } } #endregion |