using System;
using System.Threading;
namespace MediaBrowser.Common.ScheduledTasks
{
///
/// Represents a task trigger that runs repeatedly on an interval
///
public class IntervalTrigger : BaseTaskTrigger
{
///
/// Gets or sets the interval.
///
/// The interval.
public TimeSpan Interval { get; set; }
///
/// Gets or sets the timer.
///
/// The timer.
private Timer Timer { get; set; }
///
/// Stars waiting for the trigger action
///
protected internal override void Start()
{
DisposeTimer();
Timer = new Timer(state => OnTriggered(), null, Interval, TimeSpan.FromMilliseconds(-1));
}
///
/// Stops waiting for the trigger action
///
protected internal override void Stop()
{
DisposeTimer();
}
///
/// Disposes this instance.
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected override void Dispose(bool dispose)
{
if (dispose)
{
DisposeTimer();
}
base.Dispose(dispose);
}
///
/// Disposes the timer.
///
private void DisposeTimer()
{
if (Timer != null)
{
Timer.Dispose();
}
}
}
}