//First Create Empty project in sharepoint
//after that create one cs file in this project
//write following code in CS file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace timerjobApplication
{
class CustomTimerJob:SPJobDefinition
{
public CustomTimerJob() : base() { }
public CustomTimerJob(string jobName, SPService service) :
base(jobName, service, null, SPJobLockType.None)
{
this.Title = "Task Complete Timer";
}
public CustomTimerJob(string jobName, SPWebApplication webapp) :
base(jobName, webapp, null, SPJobLockType.ContentDatabase)
{
this.Title = "Task Complete Timer";
}
public override void Execute(Guid targetInstanceId)
{
SPWebApplication webApp = this.Parent as SPWebApplication;
SPList taskList = webApp.Sites[0].RootWeb.Lists["Tasks"];
SPListItem newTask = taskList.Items.Add();
newTask["Title"] = "New Task" + DateTime.Now.ToString();
newTask.Update();
}
}
}
//After that go to feature file of this solution
// in feature file call the function for timer job in feature Activated method
CreateJob(parentWebApp);
//After that write below function for timer job in same feature file
private bool CreateJob(SPWebApplication site)
{
bool jobCreated = false;
try
{
CustomTimerJob job = new CustomTimerJob(JobName, site);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 3;
job.Schedule = schedule;
job.Update();
}
catch (Exception)
{
return jobCreated;
}
return jobCreated;
}
//After that deploy this and check the timer function working in list 'Task'This code snippet for how to Create Timer Job for Beginers.
