Soenneker.Utils.Debounce
4.0.17
Prefix Reserved
dotnet add package Soenneker.Utils.Debounce --version 4.0.17
NuGet\Install-Package Soenneker.Utils.Debounce -Version 4.0.17
<PackageReference Include="Soenneker.Utils.Debounce" Version="4.0.17" />
<PackageVersion Include="Soenneker.Utils.Debounce" Version="4.0.17" />
<PackageReference Include="Soenneker.Utils.Debounce" />
paket add Soenneker.Utils.Debounce --version 4.0.17
#r "nuget: Soenneker.Utils.Debounce, 4.0.17"
#:package Soenneker.Utils.Debounce@4.0.17
#addin nuget:?package=Soenneker.Utils.Debounce&version=4.0.17
#tool nuget:?package=Soenneker.Utils.Debounce&version=4.0.17
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.107)
- Soenneker.Extensions.ValueTask (>= 4.0.97)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Utils.Debounce:
| Package | Downloads |
|---|---|
|
Soenneker.Quark.Suite
The entire suite of Quark elements, all in one library. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.17 | 435 | 11/21/2025 |
| 4.0.16 | 374 | 11/21/2025 |
| 4.0.15 | 380 | 11/20/2025 |
| 4.0.14 | 923 | 11/6/2025 |
| 4.0.13 | 658 | 10/30/2025 |
| 4.0.12 | 177 | 10/30/2025 |
| 4.0.11 | 180 | 10/29/2025 |
| 3.0.10 | 7,523 | 9/4/2025 |
| 3.0.9 | 192 | 9/3/2025 |
| 3.0.8 | 185 | 9/3/2025 |
| 3.0.7 | 505 | 8/12/2025 |
| 3.0.6 | 176 | 8/11/2025 |
| 3.0.5 | 279 | 8/11/2025 |
| 3.0.4 | 359 | 8/6/2025 |
| 3.0.3 | 252 | 8/1/2025 |
| 3.0.2 | 105 | 8/1/2025 |
| 3.0.1 | 101 | 8/1/2025 |