AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. Configuration
  3. Scheduled tasks

Scheduled tasks


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Creating a scheduled task
  • Updating a scheduled task
  • Updating multiple scheduled tasks
  • Executing a scheduled task
  • Deleting a scheduled task

Creating a scheduled task

C#
// Creates a new scheduled task object
TaskInfo newTask = new TaskInfo();

// Sets the basic task properties
newTask.TaskDisplayName = "New task";
newTask.TaskName = "NewTask";
newTask.TaskAssemblyName = "CMS.WorkflowEngine";
newTask.TaskClass = "CMS.WorkflowEngine.ContentPublisher";
newTask.TaskSiteID = SiteContext.CurrentSiteID;
newTask.TaskEnabled = true;

// Creates the scheduling interval for the task
TaskInterval interval = new TaskInterval();

// Sets the interval properties
interval.Period = SchedulingHelper.PERIOD_DAY;
interval.StartTime = DateTime.Now;
interval.Every = 2;
interval.Days = new System.Collections.Generic.List<DayOfWeek>()
{
    DayOfWeek.Monday,
    DayOfWeek.Sunday,
    DayOfWeek.Thursday
};

// Assigns the interval settings to the task
newTask.TaskInterval = SchedulingHelper.EncodeInterval(interval);

// Calculates the first run time for the new task
newTask.TaskNextRunTime = SchedulingHelper.GetFirstRunTime(interval);

// Saves the scheduled task to the database
TaskInfo.Provider.Set(newTask);
> Back to list of examples

Updating a scheduled task

C#
// Gets the scheduled task
// Provide the site ID to get site-related scheduled tasks. For global tasks, use zero (0) as the site ID.
TaskInfo updateTask = TaskInfo.Provider.Get("NewTask", SiteContext.CurrentSiteID);
if (updateTask != null)
{
    // Updates the task properties
    updateTask.TaskDisplayName = updateTask.TaskDisplayName.ToLowerCSafe();

    // Saves the updated task to the database
    TaskInfo.Provider.Set(updateTask);
}
> Back to list of examples

Updating multiple scheduled tasks

C#
// Gets all enabled scheduled tasks whose code name starts with 'New'
var tasks = TaskInfo.Provider.Get()
                                .WhereStartsWith("TaskName", "New")
                                .WhereEquals("TaskEnabled", 1);

// Loops through individual tasks
foreach (TaskInfo task in tasks)
{
    // Updates the task properties
    task.TaskDisplayName = task.TaskDisplayName.ToUpper();

    // Saves the updated task to the database
    TaskInfo.Provider.Set(task);
}
> Back to list of examples

Executing a scheduled task

C#
// Gets the scheduled task
// Provide the site ID to get site-related scheduled tasks. For global tasks, use zero (0) as the site ID.
TaskInfo runTask = TaskInfo.Provider.Get("NewTask", SiteContext.CurrentSiteID);

if (runTask != null)
{
    // Executes (runs) the task, regardless of its interval settings
    SchedulingExecutor.ExecuteTask(runTask);
}
> Back to list of examples

Deleting a scheduled task

C#
// Gets the scheduled task
// Provide the site ID to get site-related scheduled tasks. For global tasks, use zero (0) as the site ID.
TaskInfo deleteTask = TaskInfo.Provider.Get("NewTask", SiteContext.CurrentSiteID);

if (deleteTask != null)
{
    // Deletes the scheduled task
    TaskInfo.Provider.Delete(deleteTask);
}
> Back to list of examples