我的自定义sharepoint 2010计时器作业未运行

时间:2012-12-06 06:41:07

标签: c# sharepoint sharepoint-2010 sharepoint-timer-job

我创建了一个自定义计时器服务来创建列表。它使用FeatureActivated事件在几分钟内安排。我能够全局部署解决方案。但我的计时器工作没有运行。它显示最后运行时间N / A.有没有解决方案?

我的执行方法

    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();
    }

和事件接收器类

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();
        }
    }

2 个答案:

答案 0 :(得分:0)

部署SharePoint项目时,应始终重新启动sptimer进程。尝试进入命令提示符(具有管理员访问权限)并键入:

net stop sptimerv4

然后

net start sptimerv4

您的代码现在应该可以正常工作。

答案 1 :(得分:0)

重置webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @Override public void changed(ObservableValue ov, State oldState, State newState) { if (newState == Worker.State.SUCCEEDED) { System.out.println(webEngine.getLocation()); //NEW URL } } }); 上的Central Administration Pool。这似乎是工作陷入困境。随着池重置,一切都会重新开始工作。