From time to time you may need to execute arbitrary code on a schedule. DotNetNuke provides an easy API for creating scheduled tasks. In order to create a scheduled task for DotNetNuke you inherit from their SchedulerClient base class and override the DoWork() method. Below is a very simplistic class to give you an example implementation.
namespace AppTheory.Modules.MyScheduledTask
{
public class MyScheduledTask : SchedulerClient
{
public MyScheduledTask(ScheduleHistoryItem historyItem)
{
ScheduleHistoryItem = historyItem;
}
public override void DoWork()
{
try
{
Progressing();
//do something here
ScheduleHistoryItem.Succeeded = true;
ScheduleHistoryItem.AddLogNote("Overall MyScheduledTask completed successfully");
}
catch (Exception exc)
{
ScheduleHistoryItem.Succeeded = false;
ScheduleHistoryItem.AddLogNote(
string.Format("MyScheduledTask failed with exc of {0}", exc.Message));
Errored(ref exc);
Exceptions.LogException(exc);
}
}
}
}
After you have your class created you must then go to Host > Schedule in your portal and 'Add Item To Schedule' from the module actions menu. You will need to fill in a few basic pieces of configuration information for your scheduled task, and you should be all set. You can see a screen shot of schedule item detail page below.

Posted in:
DotNetNuke Tips & Tricks on Tuesday, August 26, 2008 3:17 PM by Scott Schecter