Problem with ScheduledTask - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Problem with ScheduledTask

  • Problem with ScheduledTask
  • Hi,

    I'm using Sitefinity SDK 9.2, I'm trying to create a scheduled task for send a notification to all users of my site. I create the task but never executed. What could be the problem?

    A sample of code that I'm using:

    The ScheduledTask class:

    public class SendWeeklyEmailSummaryTask : ScheduledTask

    // Inject dependencies 

    public SendWeeklyEmailSummaryTask()

    Key = SendWeeklyEmailSummaryTaskKey;


    public static void CreateTask()

    var manager = SchedulingManager.GetManager();
    var title = "SendWeeklyEmailSummaryTask";

    var tasks = manager.GetTaskData().Where(i => i.Title == title);

    foreach (var task in tasks)

    manager.DeleteTaskData(task);


    var date = DateTime.UtcNow.Date.AddSeconds(30.0);
    //var nextWeekend = LocalizationService.GetNextWeekend(DateTime.UtcNow.Date, DayOfWeek.Saturday);
    var newTask = new SendWeeklyEmailSummaryTask

    Title = title,
    ExecuteTime = date,
    Enabled = true
    ;

    manager.AddTask(newTask);
    manager.SaveChanges();


    public override void ExecuteTask()

    var notification = new NotificationServiceSnippetWeeklyActivitySummary(UserRepositoryInstance, WidgetServiceInstance, EvemtRepositoryInstance, ExternalUserRepositoryInstance);
    notification.SenEmails();


    public override string TaskName => "SitefinityWebApp.Tasks.SendWeeklyEmailSummaryTask";

    public static readonly string SendWeeklyEmailSummaryTaskKey = "SendWeeklyEmailSummaryTask";

    I'm register the task at Bootstrapper_Bootstrapped event of Application_Start.