Click or drag to resize

IDaemonService Interface


Namespace: SanteDB.Core.Services
Assembly: SanteDB.Core.Api (in SanteDB.Core.Api.dll) Version: 3.0.2081-alpha+b4ae72647f2cc271f89142f76fff26ad69e00f5a
Syntax
public interface IDaemonService : IServiceImplementation

The IDaemonService type exposes the following members.

Properties
 NameDescription
Public propertyIsRunning Indicates whether the daemon service is running
Public propertyServiceName Gets the service name
(Inherited from IServiceImplementation)
Top
Methods
 NameDescription
Public methodStart Indicates the caller wishes to start the daemon service lifecycle
Public methodStop Indicates the caller wishes to stop the daemon service
Top
Events
 NameDescription
Public eventStarted Fired when the daemon service has completed it start procedure.
Public eventStarting Fired when the daemon service has commenced start but has not yet finished
Public eventStopped Fired when the daemon has completed its stop procedure
Public eventStopping Fired when the daemon service has commenced stop but has not yet been fully shut down.
Top
Remarks

In SanteDB (and OpenIZ) a daemon service is an actively executed service which is started on application host start and torn down/stopped on application context shutdown (or when initiated by a user).

The Start method is invoked on startup. It is expected that implementer of this class will raise the Starting event to signal to other services in the application context that this particular service is starting. Once the initialization process is complete, the implementation should call the Started event to signal this service has completed its necessary start, before returning true from the start method. This behavior allows chaining of dependent services together (i.e. don't start until after start of another service)

On service teardown the Stop method is called, again it is expected that implementers will raise Stopping and then Stopped

If the daemon also implements the .NET IDisposable interface, then the Dispose method is called after service shutdown.

Example
Implementing a Daemon Service
public class HelloWorldDaemon : IDaemonService {

    public event EventHandler Starting;

    public event EventHandler Started;

    public event EventHandler Stopping;

    public event EventHandler Stopped;

    public bool Start() {
        this.Starting?.Invoke(this, EventArgs.Empty);
        Console.WriteLine("Hello World!");
        this.Started?.Invoke(this, EventArgs.Empty);
        return true;
    }

    public bool Stop() {
        this.Stopping?.Invoke(this, EventArgs.Empty);
        Console.WriteLine("Goodbye World!");
        this.Stopped?.Invoke(this, EventArgs.Empty);
        return true;
    }
}
See Also