Click or drag to resize

IJob Interface

Defines a regular schedule system background task

Namespace:  SanteDB.Core.Jobs
Assembly:  SanteDB.Core.Api (in SanteDB.Core.Api.dll) Version: 2.2.1
Syntax
public interface IJob

The IJob type exposes the following members.

Properties
  NameDescription
Public propertyCanCancel
True if the job can be cancelled
Public propertyCurrentState
Gets the current status of the job
Public propertyDescription
Gets the description of the job
Public propertyId
A unique identifier for this job
Public propertyLastFinished
Gets the time the job last finished
Public propertyLastStarted
Gets the time the job last started
Public propertyName
The name of the job
Public propertyParameters
Get the parameter definitions
Top
Methods
  NameDescription
Public methodCancel
Cancel the job
Public methodRun
Execute the job
Top
Examples
C#
public class HelloWorldJob : IJob {

    private bool m_cancelRequested = false;

    public Guid Id => Guid.NewGuid();

    public string Name => "Hello World Job!";

    public bool CanCancel => true;

    public IDictionary<String, Type> Parameters => null;

    public JobStateType CurrentState { get; private set; }

    public DateTime? LastStarted { get; private set; }

    public DateTime? LastFinished { get; private set; }

    public void Cancel() {
        this.m_cancelRequested = true;
    }

    public void Run(object sender, EventArgs e, object[] parameters) {
        try {
            this.CurrentState = JobStateType.Running;
            this.LastStart = DateTime.Now;
            this.m_cancelRequested = false;
            while(!this.m_cancelRequested) {
                Console.Writeline("Hello World!");
            }
            if(this.m_cancelRequested) {
                this.CurrentState = JobStateType.Cancelled;
            }
            else {
                this.CurrentState = JobStateTime.Complete;
            }
            this.LastFinished = DateTime.Now;
        }
        catch(Exception e) {
            this.CurrentState = JobStateType.Aborted;
        }
    }
}
See Also