# Debounce

## Debounce Class

The Debounce class is a utility class in C# used to prevent the rapid firing of events. Particularly useful in scenarios where an action should only be performed after an event has ceased to occur for a specified duration, like key-up events on textboxes that trigger searches.

### Bounce Method

The `Bounce` method is called whenever an event occurs. It resets the debounce timeout. If this method is not called again within that timeout, the action specified in the Debounce constructor will fire. The `Bounce` method can optionally take a parameter, which will be passed to the action when it fires.

#### Example:

```csharp
var debouncer = new Debounce(() => {
    //Perform action here after debounce has fired
});

debouncer.Bounce();
debouncer.Bounce();


var debouncer_int = new Debounce<int>((i) => {
    //Perform action here after debounce has fired, in this case, (i = 3) is received
});

debouncer_int.Bounce(1);
debouncer_int.Bounce(2);
debouncer_int.Bounce(3);
```

In the first example, the `Bounce` method is called without a parameter, so when the action fires it won't receive any parameters. In the second example, the `Bounce` method is called with an integer parameter, so the action will receive the last integer passed when it fires.

### Disposing

When disposing the <mark style="color:blue;">**Debounce**</mark> class that doesn't take any generic parameters, no additional callbacks will be fired.

When disposing the <mark style="color:blue;">**Debounce\<T>**</mark> class, there is an immediate one time fire of the bounce callback that has the latest value supplied. This is particularly useful when you need to dispose of a resource quickly, but still need to access the latest value in the pipeline without waiting on the bounce to fire.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.perigee.software/core-modules/utility-classes/debounce.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
