You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
652 B
28 lines
652 B
10 years ago
|
using System;
|
||
|
|
||
|
namespace NzbDrone.Common.TPL
|
||
|
{
|
||
|
public class Debouncer
|
||
|
{
|
||
|
private readonly Action _action;
|
||
|
private readonly System.Timers.Timer _timer;
|
||
|
|
||
|
public Debouncer(Action action, TimeSpan debounceDuration)
|
||
|
{
|
||
|
_action = action;
|
||
|
_timer = new System.Timers.Timer(debounceDuration.TotalMilliseconds);
|
||
|
_timer.Elapsed += timer_Elapsed;
|
||
|
}
|
||
|
|
||
|
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||
|
{
|
||
|
_timer.Stop();
|
||
|
_action();
|
||
|
}
|
||
|
|
||
|
public void Execute()
|
||
|
{
|
||
|
_timer.Start();
|
||
|
}
|
||
|
}
|
||
|
}
|