You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ToolkitSample(id:nameof(KeyboardDebounceSample),"DispatcherQueueTimer Debounce Keyboard",description:"A sample for showing how to use the DispatcherQueueTimer Debounce extension to smooth keyboard input.")]
The `DispatcherQueueTimerExtensions` static class provides a collection of extensions methods for [`DispatcherQueueTimer`](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.dispatching.dispatcherqueue) objects that make it easier to execute code on a specific UI thread at a specific time.
16
+
17
+
## Syntax
18
+
19
+
The `DispatcherQueueTimerExtensions` static class currently exposes a single extension method, `Debounce`. This is a standard technique used to rate-limit input from a user to not overload requests on an underlying service of query elsewhere.
20
+
21
+
It can be used in a number of ways, but most simply like so:
22
+
23
+
> [!SAMPLE KeyboardDebounceSample]
24
+
25
+
## Examples
26
+
27
+
You can find more examples in the [unit tests](https://github.com/CommunityToolkit/Windows/blob/rel/8.1.240916/components/Extensions/tests/DispatcherQueueTimerExtensionTests.cs).
/// <para>Used to debounce (rate-limit) an event. The action will be postponed and executed after the interval has elapsed. At the end of the interval, the function will be called with the arguments that were passed most recently to the debounced function.</para>
23
+
/// <para>Used to debounce (rate-limit) an event. The action will be postponed and executed after the interval has elapsed. At the end of the interval, the function will be called with the arguments that were passed most recently to the debounced function. Useful for smoothing keyboard input, for instance.</para>
24
24
/// <para>Use this method to control the timer instead of calling Start/Interval/Stop manually.</para>
25
25
/// <para>A scheduled debounce can still be stopped by calling the stop method on the timer instance.</para>
26
26
/// <para>Each timer can only have one debounced function limited at a time.</para>
27
27
/// </summary>
28
28
/// <param name="timer">Timer instance, only one debounced function can be used per timer.</param>
29
29
/// <param name="action">Action to execute at the end of the interval.</param>
30
30
/// <param name="interval">Interval to wait before executing the action.</param>
31
-
/// <param name="immediate">Determines if the action execute on the leading edge instead of trailing edge.</param>
31
+
/// <param name="immediate">Determines if the action execute on the leading edge instead of trailing edge of the interval. Subsequent input will be ignored into the interval has completed. Useful for ignore extraneous extra input like multiple mouse clicks.</param>
0 commit comments