// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// An Action processor that supports queueing/delayed action processing.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Utilities
{
using System;
using System.Timers;
///
/// An Action processor that supports queueing/delayed action processing.
///
public class DelayedActionProcessor
{
///
/// The task.
///
private Action task;
///
/// The timer.
///
private Timer timer;
///
/// The set task.
///
///
/// The task reset.
///
///
/// The timems.
///
public void PerformTask(Action taskReset, int timems)
{
if (timer != null)
{
timer.Stop();
timer.Close();
}
timer = new Timer(timems) { AutoReset = true };
timer.Elapsed += this.timer_Elapsed;
task = taskReset;
timer.Stop();
timer.Start();
}
///
/// The timer_ elapsed.
///
///
/// The sender.
///
///
/// The e.
///
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (task != null)
{
timer.Stop();
task();
}
}
}
}