DebounceHelper.cs 657 字节
using System;
using System.Windows.Forms;

public class DebounceHelper<T1,T2>
{
    private Timer timer;

    public event EventHandler<T2> DebouncedTextChanged;
    T1 Object;
    T2 Value;
    public DebounceHelper(int debounceInterval)
    {
        timer = new Timer();
        timer.Interval = debounceInterval;
        timer.Tick += Timer_Tick;
    }

    public void HandleTextChanged(T1 obj,T2 value)
    {
        Object = obj;
        Value=value;
        timer.Stop();
        timer.Start();
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
        timer.Stop();
        DebouncedTextChanged?.Invoke(Object, Value);
    }
}