Subscribe to this Blog

 

Contact Us!

 
AppTheory wants to talk to you about your business requirements.

Click Contact to fill out an online requirements questionnaire.

Thanks!

 

DotNetNuke Blogs

 

Current Articles | Archives | Search

Create A DotNetNuke Scheduled Task

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.

scheduledtask


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

COMMENTS

Stephan Henn
# Stephan Henn
Thursday, September 04, 2008 6:54 AM
Thanks, just what I was looking for. But unfortunately I cannot get it working.
I translated the code in vb using an online translator [http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx], made a project in VB Studio 2005 Express, created a class file, compiled it, deployed the .dll in the dnn bin folder and set up the sheduler using AppTheory.Modules.MyScheduledTask.MyScheduledTask as ClassName and the Name of the .dll (without the .dll). However, nothing happens: no entry in the log file, no error in the event log?
your's
felix
Scott Schecter
# Scott Schecter
Monday, September 29, 2008 11:44 AM
I would suggest opening your assembly with reflector and make sure you have the correct 'Full Class Name And Assembly' in. You should be able to set a breakpoint in your scheduled task, and then update the task. If you have the correct info in you should hit your breakpoint. Hope that helps...
Laurence
# Laurence
Thursday, November 13, 2008 7:34 AM
If I have the scheduler running on Timer Method I understand it runs in a dedicated thread and not inside a web user's request. Does that mean a task won't time out if it runs for a long time? I have designed a task to send out emails to customers and this could take more than 1 minute in cases where there were a lot to go out. Is it safe to let a task run for this long using Timer Method?
Scott Schecter
# Scott Schecter
Wednesday, December 03, 2008 4:12 PM
@Laurence it should be, you might want to add a check to your task though so it can tell if it is still running or not though.
Only registered users may post comments.
Privacy Statement | Terms Of Use
Copyright © 2009 AppTheory
Trend Influence TrendCRM AppTheory