Table of Contents

Class Debouncer

Namespace
MADE.Threading
Assembly
MADE.Threading.dll

Defines a debouncer that delays execution of an action until a specified period of inactivity has elapsed.

public sealed class Debouncer : IDisposable
Inheritance
Debouncer
Implements
Inherited Members
Extension Methods

Remarks

This is useful for scenarios where rapid invocations should be collapsed into a single execution, such as search-as-you-type or window resize handling.

Properties

Delay

Gets or sets the delay period. Each invocation resets the timer.

public TimeSpan Delay { get; set; }

Property Value

TimeSpan

Methods

Cancel()

Cancels any pending debounced action.

public void Cancel()

Debounce(Action)

Debounces the specified action. If called again before the Delay elapses, the previous pending invocation is cancelled.

public void Debounce(Action action)

Parameters

action Action

The action to execute after the delay.

Exceptions

ArgumentNullException

Thrown if the action is null.

ObjectDisposedException

Thrown if the debouncer has been disposed.

DebounceAsync(Func<Task>)

Debounces the specified asynchronous action. If called again before the Delay elapses, the previous pending invocation is cancelled.

public void DebounceAsync(Func<Task> action)

Parameters

action Func<Task>

The asynchronous action to execute after the delay.

Exceptions

ArgumentNullException

Thrown if the action is null.

ObjectDisposedException

Thrown if the debouncer has been disposed.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()