Click or drag to resize

ScheduledHandler Class

Base class to use when implementing a scheduled task.
Inheritance Hierarchy

Namespace:  NetQuarry
Assembly:  EAP.Core (in EAP.Core.dll) Version: 2.0.0.0 (4.6.8.0)
Syntax
public abstract class ScheduledHandler : ICmdHandler

The ScheduledHandler type exposes the following members.

Constructors
  NameDescription
Protected methodScheduledHandler
Initializes a new instance of the ScheduledHandler class
Top
Properties
  NameDescription
Public propertyApplication
Returns the application object
Public propertyIsServiceStopped
Returns true if the service has stopped. Services should check the value of this property to ensure smooth shutdown of the service.
Public propertyProperties
Returns the object's configuration properties
Public propertyRunDays
Returns the days that this task should run
Public propertyTaskID
The ID of the task as used in xmt_scheduled_tasks and xot_task_history.
Public propertyTaskState
The task state data, from xot_task_history.task_state. This state belongs to the task itself and can be used by the task as it sees fit. The latest value of the state is provided to the task, when run, via this property, and any updated value is retrieved from this property and persisted back to xot_task_history.task_state when the tasks completes.

For example, this state could be used to store the sequence number of the last item processed so that on the next iteration of the task processing could begin from the next sequence number.

Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExec
Executes a command.
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnExec
Abstract Exec handler. Derived classes must implement this method.
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodEqualValue
Determines if the object value is equal to another object. If the two objects are null, then this returns true. There is special handling for guid comparisons (since a guid could be a string formatted in up to 3 different ways). If the special guid handling is not performed, then the object.Equals method is used.
(Defined by EAPUtil.)
Top
Remarks
If you want your component to be scheduled, you should regularly check the value of the IsServiceStopped property.
Examples
The following class derives from ScheduledHandler, responds to the Exec command, and loops until the IsServiceStopped property is true.
public class SendMail : ScheduledHandler
{            
    public SendMail() {}

    protected override void OnExec(int cmdID, params object[] args)
    {
        if (cmdID == 1)
        {
            DoSendMail();
        }
    }

    private void DoSendMail()
    {
        while (true)
        {
            System.Threading.Thread.Sleep(1000);

            if (IsServiceStopped)
            {
                DevLog.LogMessage("SendMail.DoSendMail", "sendMailStopped", "Service has been stopped, exiting send mail.", LogMessageLevel.Info);
                break;
            }
            else
            {
                DevLog.LogMessage("SendMail.DoSendMail", "sendMailRun", "Sending mail...", LogMessageLevel.Info);
                //--- do work here
            }
        }
    }
}
See Also