Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Microsoft online code analysis framework , as we know i used to analyze the code [.wsp]

My code contains the timer job which is activated via feature. After running the MSOCAF on my WSP , i get warning as :

Implementation of Timer Job

Resolution : FeatureActivated event of SPFeatureReceiver does not contain the definition for job exist check. First verify if there exist any job with the same name. If exists delete the existing job and then use the new.

Code :

// make sure the job isn't already registered
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
    if (job.Name == TASK_LOGGER_JOB_NAME)
    {
         job.Delete();
         break; 
    }
}

Let me know how to delete job so as to remove the MSOCAF warning.

share|improve this question
add comment

1 Answer

Looking at the rule's internals using Reflector tells me you are required to pass the following, in order for the rule not to trigger:

You must use (in FeatureActivated):

  • Call new Microsoft.SharePoint.SPMinuteSchedule()
  • and Get Microsoft.SharePoint.Administration.SPJobDefinition.Schedule
  • and Call Microsoft.SharePoint.Administration.SPPersistedObject.Update
  • and Get Microsoft.SharePoint.Administration.SPWebApplication.JobDefinitions

You must use (in FeatureDeactivated):

  • Get Microsoft.SharePoint.Administration.SPWebApplication.JobDefinitions
  • and Call Microsoft.SharePoint.Administration.SPPersistedObject.Delete

Exactly how to write the code isn't specified in the code of the rule.

But I'm guessing this will come close: http://www.sharepointkings.com/2009/04/creating-and-working-with-sharepoint.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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