using System; using System.Threading.Tasks; namespace MediaBrowser.Common.ScheduledTasks { /// /// Use to indicate that a scheduled task should run /// public abstract class BaseTaskTrigger : IDisposable { /// /// Fires when the trigger condition is satisfied and the task should run /// internal event EventHandler Triggered; /// /// Called when [triggered]. /// protected async void OnTriggered() { Stop(); if (Triggered != null) { Triggered(this, EventArgs.Empty); } await Task.Delay(1000).ConfigureAwait(false); Start(); } /// /// Stars waiting for the trigger action /// protected internal abstract void Start(); /// /// Stops waiting for the trigger action /// protected internal abstract void Stop(); /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Releases unmanaged and - optionally - managed resources. /// /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool dispose) { if (dispose) { Stop(); } } } }