# EventDispatcherGate

> Gates control when the dispatcher processes events.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.UIElements](/engine/6000.3/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [IEquatable\<EventDispatcherGate>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct EventDispatcherGate : IDisposable, IEquatable<EventDispatcherGate>
```

## Remarks

Here is an example of using a gate:

When the gate is instantiated, it closes automatically, causing the dispatcher to store the events it receives in a queue. At the end of the `using` block, [EventDispatcherGate.Dispose](/engine/6000.3/script-reference/unityengine/uielements/eventdispatchergate/dispose.md) is called, which triggers opening the gate. When all gates on a dispatcher open, the events stored in the queue are processed. Closing a gate while the event queue is processed does not stop it from being processed. Instead, a new queue is created to store new events.

Here is an example of using a gate:

## Examples

```csharp
public class MyElement : VisualElement
{
    void Foo()
    {
        using (new EventDispatcherGate(dispatcher))
        {
            // do something that sends events
        }
    }
}
```

## Constructors

| Constructor                                                                                                                                       | Description  |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| [EventDispatcherGate(UnityEngine.UIElements.EventDispatcher)](/engine/6000.3/script-reference/unityengine/uielements/eventdispatchergate/ctor.md) | Constructor. |

## Methods

| Method                                                                                           | Description                                                                                                      |
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| [Dispose](/engine/6000.3/script-reference/unityengine/uielements/eventdispatchergate/dispose.md) | Implementation of IDisposable.Dispose. Opens the gate. If all gates are open, events in the queue are processed. |
