簡體   English   中英

我的自定義SharePoint 2010計時器作業未運行

[英]My custom sharepoint 2010 Timer job not running

我已經創建了一個自定義計時器服務來創建列表。 使用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();
        }
    }

部署SharePoint項目時,應始終重新啟動sptimer進程。 嘗試進入命令提示符(具有管理員訪問權限),然后鍵入:

net stop sptimerv4

然后

net start sptimerv4

您的代碼現在應該可以正常工作了。

重置Internet Information Services上的Central Administration Pool 似乎是工作停滯了。 重置池后,一切將重新開始。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM