2019-12-04 18:57:18 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2019-12-08 19:54:52 +01:00
|
|
|
|
namespace Swan.Threading {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Defines a standard API to control background application workers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IWorker {
|
2019-12-04 18:57:18 +01:00
|
|
|
|
/// <summary>
|
2019-12-08 19:54:52 +01:00
|
|
|
|
/// Gets the current state of the worker.
|
2019-12-04 18:57:18 +01:00
|
|
|
|
/// </summary>
|
2019-12-08 19:54:52 +01:00
|
|
|
|
WorkerState WorkerState {
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether this instance is disposed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// <c>true</c> if this instance is disposed; otherwise, <c>false</c>.
|
|
|
|
|
/// </value>
|
|
|
|
|
Boolean IsDisposed {
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether this instance is currently being disposed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// <c>true</c> if this instance is disposing; otherwise, <c>false</c>.
|
|
|
|
|
/// </value>
|
|
|
|
|
Boolean IsDisposing {
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the time interval used to execute cycles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
TimeSpan Period {
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name identifier of this worker.
|
|
|
|
|
/// </summary>
|
|
|
|
|
String Name {
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Starts execution of worker cycles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The awaitable task.</returns>
|
|
|
|
|
Task<WorkerState> StartAsync();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pauses execution of worker cycles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The awaitable task.</returns>
|
|
|
|
|
Task<WorkerState> PauseAsync();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resumes execution of worker cycles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The awaitable task.</returns>
|
|
|
|
|
Task<WorkerState> ResumeAsync();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Permanently stops execution of worker cycles.
|
|
|
|
|
/// An interrupt is always sent to the worker. If you wish to stop
|
|
|
|
|
/// the worker without interrupting then call the <see cref="PauseAsync"/>
|
|
|
|
|
/// method, await it, and finally call the <see cref="StopAsync"/> method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The awaitable task.</returns>
|
|
|
|
|
Task<WorkerState> StopAsync();
|
|
|
|
|
}
|
2019-12-04 18:57:18 +01:00
|
|
|
|
}
|