Scheduling a custom code

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The process of scheduling includes two steps: writing code to perform required action and creating the scheduled task.

 

Writing task code

 

Task code must be placed into a specific class method.

 

1.Create a new library (assembly) as a part of your solution and a new class inside this library. The following example uses assembly name CMS.Ecommerce and class CMS.Ecommerce.ShoppingCartCleaner, however, you will need to use your own names. References to these dlls must be added to the newly created project:

 

CMS.Scheduler.dll

CMS.Staging.dll

CMS.DataEngine.dll

CMS.SettingsProvider.dll

 

 

2.Define method Execute(TaskInfo task) which will be performed when task is executed:

 

[C#]

 

using CMS.Scheduler;

namespace CMS.Ecommerce

{

  /// <summary>

  /// Provides an ITask interface to delete old shopping carts.

  /// </summary>

  public class ShoppingCartCleaner : ITask

   {

      public string Execute(TaskInfo task)

       {

          try

           {

 

              // Here comes the task code

 

              return null;

           }

          catch (Exception ex)

           {

              return (ex.Message);

           }

       }

   }

}

 

3.Compile the library.

 

 

Creating a new task

 

1.Go to Site Manager -> Administration -> Scheduled tasks.
2.Select site the task should be scheduled for.
3.Click New task.
4.Specify task properties:

 

Task display name

Name used for Scheduled Task.

Task name

Scheduled Task name used in code.

Task assembly name

Name of the assembly.

Task class name

Name of the class.

Task interval

Time interval when the task should be run.

Task data

Data which should be provided to assembly.

Task enabled

Indicates if the task is enabled.

Delete task after last run

Indicates if the task should be deleted after last run.

Server name

Name of the server where the task is run.

Create tasks for all web farm servers

If checked, tasks will be created for all web farm servers and the Server name field will be grayed out.

 

5.Click OK.
6.The task is scheduled.

 

devguide_clip0395

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?scheduling_a_custom_code.htm