Soenneker.Utils.Debounce
4.0.48
Prefix Reserved
dotnet add package Soenneker.Utils.Debounce --version 4.0.48
NuGet\Install-Package Soenneker.Utils.Debounce -Version 4.0.48
<PackageReference Include="Soenneker.Utils.Debounce" Version="4.0.48" />
<PackageVersion Include="Soenneker.Utils.Debounce" Version="4.0.48" />
<PackageReference Include="Soenneker.Utils.Debounce" />
paket add Soenneker.Utils.Debounce --version 4.0.48
#r "nuget: Soenneker.Utils.Debounce, 4.0.48"
#:package Soenneker.Utils.Debounce@4.0.48
#addin nuget:?package=Soenneker.Utils.Debounce&version=4.0.48
#tool nuget:?package=Soenneker.Utils.Debounce&version=4.0.48
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
Interlockedswaps. - 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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Soenneker.Extensions.Task (>= 4.0.121)
- Soenneker.Extensions.ValueTask (>= 4.0.113)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Utils.Debounce:
| Package | Downloads |
|---|---|
|
Soenneker.Quark.Suite
Shadcn-powered Blazor UI, refined and modular. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.48 | 1,149 | 4/23/2026 |
| 4.0.47 | 87 | 4/22/2026 |
| 4.0.46 | 10,099 | 3/13/2026 |
| 4.0.45 | 132 | 3/13/2026 |
| 4.0.41 | 296 | 3/12/2026 |
| 4.0.40 | 133 | 3/12/2026 |
| 4.0.38 | 743 | 3/11/2026 |
| 4.0.37 | 133 | 3/11/2026 |
| 4.0.36 | 133 | 3/10/2026 |
| 4.0.35 | 119 | 3/10/2026 |
| 4.0.34 | 117 | 3/10/2026 |
| 4.0.33 | 96 | 3/9/2026 |
| 4.0.32 | 639 | 3/9/2026 |
| 4.0.31 | 1,041 | 3/4/2026 |
| 4.0.30 | 91 | 3/4/2026 |
| 4.0.29 | 95 | 3/4/2026 |
| 4.0.28 | 3,660 | 1/12/2026 |
| 4.0.27 | 820 | 1/6/2026 |
| 4.0.26 | 110 | 1/6/2026 |
| 4.0.25 | 273 | 1/3/2026 |
Various fixes