博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SharePoint 2010 Custom Timer Job
阅读量:4967 次
发布时间:2019-06-12

本文共 4553 字,大约阅读时间需要 15 分钟。

Introduction

Based on my popular articel about Creating Custom Timer Job in Sharepoint 2010,I Have decide to upload the simple code  on how to create Custom Timer Job in Sharepoint 2010 ,But first let us know more about Timer Job

  • A timer job runs in a specific Windows service for SharePoint Server.
  • Timer jobs also perform infrastructure tasks for the Timer service, such as clearing the timer job history and recycling the Timer service; and tasks for Web applications, such as sending e-mail alerts.
  • A timer job contains a definition of the service to run and specifies how frequently the service is started.
  • The SharePoint 2010 Timer service (SPTimerv4) runs timer jobs.
  • Many features in SharePoint Server rely on timer jobs to run services according to a schedule.

Building the Sample

To run the sample you just need to open it in Visual Studio 2010 then deploy it to your test machine or you can package it to deploy it in Production environment.The solution itself will create list for you and try to fill it each five minutes.

Description

Based on my knoladge Customer Timer job in sharepoint 2010 is on of the most confused approch in SharePoint Many developer stuck at some point and they do not what to do to make it run correctly.So this sample will show you how to make it happent and run Custom Timer Job to achive you tasks in simple way.

C#
//Create class derived from SPJonDefinition Class  class ListTimerJob : SPJobDefinition     {          public ListTimerJob()              : base()         {          }          public ListTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)              : base(jobName, service, server, targetType)         {          }          public ListTimerJob(string jobName, SPWebApplication webApplication)              : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)         {              this.Title = "List Timer Job";          }          public override void Execute(Guid contentDbId)         {              // get a reference to the current site collection's content database              SPWebApplication webApplication = this.Parent as SPWebApplication;              SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];              // get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database              SPList Listjob = contentDb.Sites[0].RootWeb.Lists["ListTimerJob"];              // create a new list Item, set the Title to the current day/time, and update the item              SPListItem newList = Listjob.Items.Add();              newList["Title"] = DateTime.Now.ToString();              newList.Update();          } } //Add Event receiver at Feature Level  [Guid("9a724fdb-e423-4232-9626-0cffc53fb74b")] public class Feature1EventReceiver : SPFeatureReceiver     {         const string List_JOB_NAME = "ListLogger";         // Uncomment the method below to handle the event raised after a feature has been activated.          public override void FeatureActivated(SPFeatureReceiverProperties properties)         {             SPSite site = properties.Feature.Parent as SPSite;              // make sure the job isn't already registered              foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)             {                  if (job.Name == List_JOB_NAME)                      job.Delete();              }              // install the job              ListTimerJob listLoggerJob = new ListTimerJob(List_JOB_NAME, site.WebApplication);              SPMinuteSchedule schedule = new SPMinuteSchedule();              schedule.BeginSecond = 0;              schedule.EndSecond = 59;              schedule.Interval = 5;              listLoggerJob.Schedule = schedule;              listLoggerJob.Update();          }          // Uncomment the method below to handle the event raised before a feature is deactivated.          public override void FeatureDeactivating(SPFeatureReceiverProperties properties)         {             SPSite site = properties.Feature.Parent as SPSite;              // delete the job              foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)             {                  if (job.Name == List_JOB_NAME)                      job.Delete();              }  }  //That's all

Source Code Files

  • SharePoint Project (CustomTimerJob) - contain List I
  • Source  ------http://code.msdn.microsoft.com/office/SharePoint-2010-Custom-416cd3a1

转载于:https://www.cnblogs.com/ilawrence/archive/2012/12/21/2828028.html

你可能感兴趣的文章
08.存储Cinder→5.场景学习→03.Attach Volume→2.实际操作
查看>>
R语言学习 - 线图绘制
查看>>
eos超时 锁表问题 网友办法
查看>>
Python学习笔记8(2)——序列的方法
查看>>
P3084 [USACO13OPEN]照片Photo
查看>>
matlab读取cvs文件的几种方法
查看>>
谈谈iOS Animation
查看>>
如何设置eclipse新建工程内文件的默认编码格式
查看>>
46. Permutations
查看>>
170. Two Sum III - Data structure design
查看>>
背包九讲之四(混合三种背包问题)
查看>>
hdu2544(自己实现优先队列)
查看>>
南阳242
查看>>
shell脚本去重的几种方法
查看>>
【完全开源】百度地图Web service API C#.NET版,带地图显示控件、导航控件、POI查找控件...
查看>>
Ubuntu 12.04 the system is running in low-graphics mode
查看>>
iOS开发编码建议与编程经验(书写规范)
查看>>
gerrit使用
查看>>
C博客作业01--分支、顺序结构
查看>>
递归求任意数字之间的和
查看>>