Get the task and its status

  1. Get all tasks, using the following code:
    C#
    using System.Linq;
    using Telerik.Sitefinity.Scheduling;
    using Telerik.Sitefinity.Scheduling.Model;
    
    namespace SitefinityWebApp
    {
        public partial class TaskScheduleSnippets
        {
            public void GetAllTasks()
            {
                IQueryable<ScheduledTaskData> tasks = SchedulingManager.GetManager().GetTaskData();
            }
        }
    }
  2. To check if a task is running, using the IsRunning property.
  3. To set the task progress, use the following:
    C#
    using Telerik.Sitefinity.Scheduling;
    
    namespace SitefinityWebApp
    {
        public class MyCustomTask : ScheduledTask
        {
            public override void ExecuteTask()
            {
                // After you calculate the current progress of the task, just call the UpdateProgress method
                // No need to save the changes, or anything
                int progressPercent = 15;
                this.UpdateProgress(progressPercent);
            }
        }
    }
  4. To retrieve the task progress, use the following code:
    C#
    using System.Linq;
    using Telerik.Sitefinity.Scheduling;
    
    public partial class ScheduleTaskSnippets
    {
        public void CheckTaskProgress()
        {
            var tasks = SchedulingManager.GetManager().GetTaskData();
            var myTask = tasks.Where(t => t.TaskName == "SitefinityWebApp.MyScheduledTask").FirstOrDefault();
            if (myTask != null)
            {
                var progress = myTask.Progress;
                // Use the progress of the task here
            }
        }
    }
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?