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: 3.0.2081-alpha+b4ae72647f2cc271f89142f76fff26ad69e00f5a
Syntax
public interface IJob

The IJob type exposes the following members.

Properties
 NameDescription
Public propertyCanCancel True if the job can be cancelled
Public propertyDescription Gets the description of the job
Public propertyId A unique identifier for this job
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
Example
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