c# - 我的自定义 Sharepoint 2010 计时器作业未运行

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

最佳答案

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

net stop sptimerv4

然后

net start sptimerv4

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

关于c# - 我的自定义 Sharepoint 2010 计时器作业未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13738263/

相关文章:

c# - 将不可变对象(immutable对象)持久化到关系数据库

c# - NHibernate:二级缓存过期

sharepoint - 设置基本负载测试

sharepoint - WebPart "metadata"?

c# - 如何使用 C# 在 SharePoint 中将字符串初始化为日期时间字段类型

javascript - sharepoint 2010 使用 jscript 检索查找列值

c# - 我如何在 SQL 中使用枚举而不在我的 SQL 脚本/过程中硬编码魔数(Magic Number)?

c# - 无法通过 SignalR Hub 访问 session 信息。是我的设计错了吗?

javascript - 检查 id 标签内的文本并将类添加到另一个标签

ios - Sharepoint 2010,HTML5 视频无法在 iPad 上运行