namespace VideoBrowser.Helpers
{
using System;
using System.Windows.Forms;
///
/// Defines the .
///
public class DelayCall
{
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The action.
/// The milliSecondDelay.
/// The callInUIThread.
public DelayCall(Action action, int milliSecondDelay, bool callInUIThread = false)
{
this.Action = action ?? throw new ArgumentNullException(nameof(action));
this.MilliSecondDelay = milliSecondDelay;
this.IsCallInUIThread = callInUIThread;
this.Timer = new Timer();
this.Timer.Tick += this.OnTimer_Tick;
this.Timer.Interval = this.MilliSecondDelay;
this.Timer.Stop();
}
#endregion Constructors
#region Properties
///
/// Gets the Action.
///
public Action Action { get; }
///
/// Gets a value indicating whether IsCallInUIThread.
///
public bool IsCallInUIThread { get; }
///
/// Gets or sets the MilliSecondDelay.
///
public int MilliSecondDelay { get; set; }
///
/// Gets the Timer.
///
public Timer Timer { get; }
#endregion Properties
#region Methods
///
/// The Call.
///
public void Call()
{
this.Restart();
}
///
/// The OnThick.
///
/// The state.
private void OnThick(object state)
{
this.Timer.Stop();
if (this.IsCallInUIThread)
{
UIThreadHelper.Invoke(this.Action);
}
else
{
this.Action();
}
}
///
/// The OnTimer_Tick.
///
/// The sender.
/// The e.
private void OnTimer_Tick(object sender, EventArgs e)
{
throw new NotImplementedException();
}
///
/// The Restart.
///
private void Restart()
{
this.Timer.Stop();
this.Timer.Start();
}
#endregion Methods
}
}