Class Debouncer<TData>
Object which debounces events, i.e., accumulating multiple incoming events into one with the possibility of keeping track of the incoming trigger data.
public sealed class Debouncer<TData> : DebouncerBase<DebouncedEventArgs<TData>>, IDisposable, IDebouncer<TData>, IDebouncerBase<DebouncedEventArgs<TData>>
Type Parameters
TData
- Inheritance
-
DebouncerBase<DebouncedEventArgs<TData>>Debouncer<TData>
- Implements
-
IDebouncer<TData>IDebouncerBase<DebouncedEventArgs<TData>>
- Inherited Members
Constructors
Debouncer()
Initializes a new instance of the Debouncer<TData> class.
public Debouncer()
Debouncer(TimeProvider)
Initializes a new instance of the Debouncer<TData> class using the specified System.TimeProvider.
public Debouncer(TimeProvider timeProvider)
Parameters
timeProviderTimeProviderThe System.TimeProvider to use.
Remarks
This constructor is intended for unit testing.
Properties
DataLimit
Gets or sets the maximum number of calls to Trigger(TData) after which a new Debounced event will fire.
public int DataLimit { get; set; }
Property Value
Remarks
The default value is MaxValue.
Exceptions
- ObjectDisposedException
The object has been disposed.
- ArgumentOutOfRangeException
The value is less than 1.
Methods
Reset(out IReadOnlyList<TData>)
Resets the accumulated trigger count to 0 and cancels any ongoing debouncing.
public long Reset(out IReadOnlyList<TData> data)
Parameters
dataIReadOnlyList<TData>Accumulated data from each call to Trigger(TData) since the last event handler was called.
Returns
- long
The number of triggers that had been accumulated since the last event handler was called.
Remarks
This method may be called even after Dispose() has been called.
Trigger(TData)
Accumulates one more trigger.
public void Trigger(TData data)
Parameters
dataTDataData that accompanies the trigger.
Exceptions
- InvalidOperationException
More than DataLimit calls to Trigger(TData) while an event handler is currently being invoked.
- ObjectDisposedException
The object has been disposed.