Tasks run with Windows Schedule Service throwing error

Trevor Fayas asked on March 14, 2014 11:07

I'm trying to use Windows Scheduled Service in order to run some scheduled tasks consistantly on time.

The tasks are indeed executing using the external service, but i get an error with it when when i don't use the windows scheduled service it doesn't throw the error:

Error: [ClasHelper.GetClass]: App_Code class cannot be loaded because the OnGetCustomClass handler is not initialized.

The code is indeed there for the OnGetCustomClass (below), why does it not work with windows schedular but does when i use the normal one? Here's the tasks's settings: Task Assembly name: App_Code Task Class name: NNKenticoCron.ScheduledTasks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.SettingsProvider;

[ClassLoader]
public partial class CMSModuleLoader
{
    /// <summary>
    /// Attribute class for loading custom classes.
    /// </summary>
    private class ClassLoader : CMSLoaderAttribute
    {
        /// <summary>
        /// Called automatically when the application starts.
        /// </summary>
        public override void Init()
        {
            // Assigns a handler for the OnGetCustomClass event.
            ClassHelper.OnGetCustomClass += ClassHelper_OnGetCustomClass;
        }

        /// <summary>
        /// Gets a custom class object based on the given parameters.
        /// </summary>
        private void ClassHelper_OnGetCustomClass(object sender, ClassEventArgs e)
        {
            if (e.Object == null)
            {
                // Checks the name of the requested class.
                switch (e.ClassName)
                {
                    // Gets an instance of the CustomTask class.
                    case "NNKenticoCron.ScheduledTasks":
                        e.Object = new NNKenticoCron.ScheduledTasks();
                        break;
                }
            }
        }
    }


}

Correct Answer

Juraj Ondrus answered on March 16, 2014 06:15

Hi,
Adding a class assembly is described for the older way of adding global event handlers here. You just do the same, except the web.config settings.

Best regards,
Juraj Ondrus

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on March 14, 2014 11:12

Dumb me...

"You cannot define the task in the App_Code folder if you wish to use the external service. To run a custom task externally, you must add a new assembly to your project and then define the task class there."

Any instruction on how to do this for kentico?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.