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

I have created a custom timer service to create a list. its scheduled in minute using FeatureActivated event. I could able to globally deploy the solution. But the my timer job is not running. Its showing last run time N/A. Is there any solution?

My Execute method

public override void Execute(Guid targetInstanceId) { ClientContext clientContext = new ClientContext("http://mymachine:0909"); Web site = clientContext.Web;

    ListCreationInformation listCreationInfo = new ListCreationInformation();
    listCreationInfo.Title = "Test Mailer List";
    listCreationInfo.TemplateType = (int)ListTemplateType.GenericList;
    List list = site.Lists.Add(listCreationInfo);

    Field field1 = list.Fields.AddFieldAsXml(
              @"<Field Type='Choice'
              DisplayName='Category'
              Format='Dropdown'>
         <Default>Specification</Default>
         <CHOICES>
           <CHOICE>Specification</CHOICE>
           <CHOICE>Development</CHOICE>
           <CHOICE>Test</CHOICE>
           <CHOICE>Documentation</CHOICE>
         </CHOICES>
       </Field>", true, AddFieldOptions.DefaultValue);
    Field field2 = list.Fields.AddFieldAsXml(
        @"<Field Type='Number'
              DisplayName='Estimate'/>", true, AddFieldOptions.DefaultValue);
    clientContext.ExecuteQuery();
}

And Event receiver class

public class Feature1EventReceiver : SPFeatureReceiver {

public const string jobName = "BdayTimer";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
    DeleteJob(webApp.JobDefinitions);
    TimerJobTest myJob = new TimerJobTest(webApp);

    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 1;

    myJob.Schedule = schedule;
    myJob.Update();

}


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

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
    DeleteJob(webApp.JobDefinitions);
}

public void DeleteJob(SPJobDefinitionCollection job1)
{
    foreach (SPJobDefinition job in job1)
    {
        if (job.Name.Equals(jobName))
            job.Delete();
    }
share|improve this question
    
Check out the ULS logs? –  David Lozzi Dec 6 '12 at 12:50
    
Have you restarted the Timer Service (SPTimerV4) since deploying your WSP? –  TZHX Dec 6 '12 at 12:51
    
and are you sure properties.Feature.Parent is an SPWebApplication (rather than an SPSite?) –  TZHX Dec 6 '12 at 15:04
    
I have checked the ULS logs , also tried restarting its not executing. But its working fine in another server. –  Ananthu Dec 10 '12 at 9:46
    
Could it be the wrong system time on your server that does not work properly with your timer job? –  Denis Molodtsov Jul 15 '13 at 7:56
add comment

2 Answers

Can you try the following steps if you are doing it on dev VM:

After deployment of the WSP and activating the feature, restrat timer service. In Visual studio attach OWSTimer process and attach breakpoint at Execute method. Then go to the Timer Job definition and select the timer job and click Run Now.

share|improve this answer
    
I have done that too. Still no hope. Buts its working fine in another server. –  Ananthu Dec 10 '12 at 9:55
    
I'm facing the same issue. Difference is that on production server farm has 3 web applications, on dev one there is only 1 –  christof Dec 21 '12 at 9:49
add comment

go through below link, its working perfectly...

http://www.thesharepointblog.net/Lists/Posts/Post.aspx?List=815f255a-d0ef-4258-be2a-28487dc9975c&ID=57

share|improve this answer
    
My code is working fine on another server. I cant figure out the issue. –  Ananthu Dec 10 '12 at 9:53
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.