1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Problem with ScheduledTask

Problem with ScheduledTask

1 posts, 0 answered
  1. Jesús
    Jesús avatar
    0 posts
    Registered:
    24 Nov 2016
    11 May
    Link to this post

    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.

1 posts, 0 answered