无锡企业网站制作报价,中装建设集团股份有限公司,建站公司 网络服务,美食网页设计作品首先介绍一下什么是定时器作业#xff0c;说的再多#xff0c;也不如一张图说的清楚这两张图应该把我想说的已经表达清楚了#xff0c;下一步介绍一下如何自定义Timer Job第一步#xff1a;创建一个类#xff08;CustomTimerJob.cs#xff09;第二步#xff1a;引用 usi…首先介绍一下什么是定时器作业说的再多也不如一张图说的清楚这两张图应该把我想说的已经表达清楚了下一步介绍一下如何自定义Timer Job第一步创建一个类CustomTimerJob.cs第二步引用 using Microsoft.SharePoint.Administration;并继承SPJobDefinition第三步构造 三个函数 public CustomTimerJob() : base() { } public CustomTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) { } public CustomTimerJob(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) { this.Title Custom Timer Job; //在上面的图处上可以看到这个名字 }第四步override Execute 处理自己的业务 public override void Execute(Guid targetInstanceId) { SPWebApplication webApplication this.Parent as SPWebApplication; SPContentDatabase contentDb webApplication.ContentDatabases[targetInstanceId]; // get a reference to the Tasks list in the RootWeb of the first site collection in the content database SPList taskList contentDb.Sites[0].RootWeb.Lists[Product]; // create a new task, set the Title to the current day/time, and update the item SPListItem newTask taskList.Items.Add(); newTask[Title] DateTime.Now.ToString(); newTask.Update(); }在上一篇 自定义 Features 里面当激活功能时到管理中心可以看到自己的定义的 Timer Jobpublic override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site properties.Feature.Parent as SPSite; if (site ! null) { foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name CUSTOM_TIMER_JOB) { job.Delete(); } } } //开始Job CustomTimerJob customTimerJob new CustomTimerJob(CUSTOM_TIMER_JOB, site.WebApplication); SPMinuteSchedule schedule new SPMinuteSchedule(); schedule.BeginSecond 0; schedule.EndSecond 59; schedule.Interval 5; customTimerJob.Schedule schedule; customTimerJob.Update(); }之后部署到网站网站集里停止再激活之后去管理中心就可以看到自己定义的Job了更多精彩请关注转载于:https://www.cnblogs.com/Fengger/archive/2012/06/02/2532047.html