using System; using System.Threading; using System.Threading.Tasks; namespace Implab.Components { /// /// Interface for the component which performs a long running task. /// /// /// The access to the runnable component should be sequential, the /// componet should support asynchronous completion of the initiated /// operation but operations itself must be initiated sequentially. /// public interface IRunnable { /// /// Starts this instance /// /// /// This operation is cancellable and it's expected to move to /// the failed state or just ignore the cancellation request, /// void Start(); void Start(CancellationToken ct); /// /// Stops this instance and releases all resources, after the /// instance is stopped it is moved to Disposed state and /// can't be reused. /// /// /// If the componet was in the starting state the pending operation /// will be requested to cancel. The stop operatin will be /// performed only if the component in the running state. /// void Stop(); void Stop(CancellationToken ct); /// /// Current state of the componenet, dynamically reflects the current state. /// ExecutionState State { get; } /// /// Event to monitor the state of the component. /// event EventHandler StateChanged; /// /// The last error /// Exception LastError { get; } } }