Soenneker.Utils.Debounce 3.0.10

Prefix Reserved
dotnet add package Soenneker.Utils.Debounce --version 3.0.10
                    
NuGet\Install-Package Soenneker.Utils.Debounce -Version 3.0.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Utils.Debounce" Version="3.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.Debounce" Version="3.0.10" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.Debounce" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Utils.Debounce --version 3.0.10
                    
#r "nuget: Soenneker.Utils.Debounce, 3.0.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Utils.Debounce@3.0.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Utils.Debounce&version=3.0.10
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.Debounce&version=3.0.10
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Utils.Debounce

A utility that lets you debounce work in .NET. Give it a delay, async/sync delegate, and the Debouncer guarantees that multiple rapid calls collapse into exactly one invocation.


Why would I need this?

  • API calls: Prevent hammering a server while the user types.
  • Disk I/O: Batch frequent save requests into a single write.
  • Telemetry: Send aggregated metrics after bursts of activity.
  • Search boxes / auto-complete: React only after the user pauses typing.

Quick start

dotnet add package Soenneker.Utils.Debounce
using Soenneker.Utils.Debounce;

var debouncer = new Debouncer();

// Fire only once, 300 ms after the *last* request:
void OnTextChanged(string text)
{
    debouncer.Debounce(
        delayMs: 300,
        action: async ct =>
        {
            var results = await SearchAsync(text, ct);
            UpdateUI(results);
        });
}

void OnResize()
{
    debouncer.Debounce(
        delayMs: 250,
        action: () =>
        {
            // Runs on the thread-pool after 250 ms of quiescence
            SaveWindowLayout();
        });
}
Leading-edge execution

Pass runLeading: true if you want the first call to run immediately and the trailing call to run after the quiet period:

debouncer.Debounce(
    delayMs: 500,
    runLeading: true,
    action: ct => Logger.LogAsync("Burst started", ct));

Either wrap it in a using statement or dispose the debouncer when you’re done:

await debouncer.DisposeAsync();

DisposeAsync() waits for any in-flight work to finish, ensuring graceful shutdown.


Design highlights

  • Pure TPL: Built on System.Threading.Timer
  • Thread-safe: Internal state is guarded with Interlocked swaps.
  • Cancellation-friendly: Each queued delegate receives its own CancellationToken.
  • Zero allocations on idle: Work objects are created only when you call Debounce.
  • Tested: xUnit suite covering timing, cancellation, and disposal semantics.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Utils.Debounce:

Package Downloads
Soenneker.Quark.Table

A native Blazor table component.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.10 1,483 9/4/2025
3.0.9 139 9/3/2025
3.0.8 139 9/3/2025
3.0.7 336 8/12/2025
3.0.6 135 8/11/2025
3.0.5 193 8/11/2025
3.0.4 261 8/6/2025
3.0.3 136 8/1/2025
3.0.2 62 8/1/2025
3.0.1 60 8/1/2025