Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/windows/Extensions/DispatcherQueueExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ icon: Assets/Extensions.png

The `DispatcherQueueExtensions` type provides a collection of extensions methods for [`DispatcherQueue`](/uwp/api/windows.system.dispatcherqueue) objects that makes it easier to execute code on a specific UI thread. A `DispatcherQueue` instance can be retrieved and cached for later use, and then used through any of the available helper methods to dispatch a delegate invocation on it.

## Setup

First, add the [`CommunityToolkit.WinUI.Extensions`](https://www.nuget.org/packages/CommunityToolkit.WinUI.Extensions) to your project. See [Get started](../getting-started.md). Then:

```csharp
// Imports the extension methods
using CommunityToolkit.WinUI;
```

## Syntax

The `DispatcherQueueExtensions` type exposes a number of overloads of its `EnqueueAsync` method to dispatch either synchronous or asynchronous delegates, and to optionally have them return a value that is then relayed back to the caller through an awaitable task. Here are some examples of how these extension methods can be used:

```csharp
using CommunityToolkit.WinUI;

// Get a DispatcherQueue instance for later use. This has to be called on the UI thread,
// but it can then be cached for later use and accessed from a background thread as well.
DispatcherQueue dispatcherQueue = DispatcherQueue.GetForCurrentThread();
Expand Down