IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
When you want to schedule a task for later execution, ScheduledTask and SchedulingManager are the appropriate classes to use. But getting the thread to work and execute the task is a variation from what you might expect.
ScheduledTask
SchedulingManager
The following example schedules a timed task that uploads a Youtube video file to Youtube:
public class YoutubeUploadTask : ScheduledTask {
public string videoPath { get; set; }
public string storyTitle { get; set; }
public Guid storyItemId { get; set; }
public override void ExecuteTask() {
//Upload to Youtube
YoutubeHelper.UploadVideo(videoPath, storyTitle, storyItemId);
}
ExecuteTask
public override string TaskName {
get {
return this.GetType().FullName;
public YoutubeUploadTask() {
GetCustomData
SetCustomData
public override void SetCustomData(string customData) {
var data = customData.Split('\t');
videoPath = data[0];
storyTitle = data[1];
storyItemId = Guid.Parse(data[2]);
public override string GetCustomData() {
var data = new List<
string
>() {
videoPath,
storyTitle,
storyItemId.ToString()
};
return string.Join("\t", data);
Task
//CREATING
//-------------
//You cannot EDIT the Dynamic Module Item in a new Thread:
//new Thread(() => YoutubeHelper.UploadVideo(videoPath, storyTitle, storyItem.Id)).Start();
//so a new Task is created instead
var schedMgr = SchedulingManager.GetManager();
var newTask = new YoutubeUploadTask() {
Key = Guid.NewGuid().ToString(),
ExecuteTime = DateTime.UtcNow.AddSeconds(10),
videoPath = videoPath,
storyTitle = storyTitle,
storyItemId = storyItem.Id
schedMgr.AddTask(newTask);
schedMgr.SaveChanges();
In this example:
new Task() { parameter name-value pairs };
ExecuteTime
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important