The following sample code shows how you can modify the Display name of an existing scheduled task:
[C#]
using CMS.Scheduler;
...
string taskName = "TestContentPublishing"; string siteName = "CorporateSiteASPX";
// Get task object TaskInfo ti = TaskInfoProvider.GetTaskInfo(taskName, siteName);
// If task exists if (ti != null) { // Update property ti.TaskDisplayName += " updated";
// Save to database TaskInfoProvider.SetTaskInfo(ti); } |
The following sample code shows how you can create a new scheduled task and add it to the system:
[C#]
using System; using System.Collections; using CMS.Scheduler; using CMS.CMSHelper;
...
// Create new task object TaskInfo ti = new TaskInfo();
// Set properties ti.TaskAssemblyName = "CMS.WorkflowEngine"; ti.TaskClass = "CMS.WorkflowEngine.ContentPublisher"; ti.TaskDisplayName = "Test content publishing"; ti.TaskName = "TestContentPublishing";
// Create interval TaskInterval interval = new TaskInterval();
// Set interval properties interval.Period = SchedulingHelper.PERIOD_DAY; interval.StartTime = DateTime.Now; interval.Every = 2;
// Add some days to interval ArrayList days = new ArrayList(); days.Add(DayOfWeek.Monday.ToString()); days.Add(DayOfWeek.Sunday.ToString()); days.Add(DayOfWeek.Thursday.ToString());
interval.Days = days;
ti.TaskInterval = SchedulingHelper.EncodeInterval(interval); ti.TaskSiteID = CMSContext.CurrentSiteID; ti.TaskData = "<data></data>"; ti.TaskEnabled = true; ti.TaskNextRunTime = SchedulingHelper.GetNextTime(ti.TaskInterval, DateTime.Now, DateTime.Now);
// Save to database TaskInfoProvider.SetTaskInfo(ti); |
The following sample code shows how you can delete an existing scheduled task:
[C#]
using CMS.Scheduler;
...
string taskName = "TestContentPublishing"; string siteName = "CorporateSiteASPX";
// Get task object TaskInfo ti = TaskInfoProvider.GetTaskInfo(taskName, siteName);
// If task exists if (ti != null) { // Delete from database TaskInfoProvider.DeleteTaskInfo(ti); } |
Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_managing_scheduled_tasks.htm