Share via


DispatcherQueueHandler Delegate

Definition

A callback that will be executed on the DispatcherQueue thread.

public delegate void DispatcherQueueHandler();
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 327680)]
/// [Windows.Foundation.Metadata.Guid(3751992476, 6701, 18711, 152, 242, 147, 154, 241, 214, 224, 200)]
class DispatcherQueueHandler : MulticastDelegate
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 327680)]
[Windows.Foundation.Metadata.Guid(3751992476, 6701, 18711, 152, 242, 147, 154, 241, 214, 224, 200)]
public delegate void DispatcherQueueHandler();
var dispatcherQueueHandlerHandler = function(){
/* Your code */
}
Public Delegate Sub DispatcherQueueHandler()
Attributes

Windows requirements

Device family
Windows 10 Fall Creators Update (introduced in 10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v5.0)

Examples

The following example demonstrates how to create a DispatcherQueueHandler that can be used to run code on a thread with DispatcherQueue and how to enqueue it using TryEnqueue.

Windows.System.DispatcherQueueHandler handler = () =>
                                {
                                    // code for DispatcherQueue to run
                                };

// Create a new thread and initialize a DispatcherQueueController
// and run a DispatcherQueue event loop on it.
_queueController =
    DispatcherQueueController.CreateOnDedicatedThread();
_queue = _queueController.DispatcherQueue;

// This is the first TryEnqueue() after creating the DispatcherQueue
// The callback is guaranteed to be invoked first despite Priority on the
// newly created thread.

// Attempt to enqueue the handler and check if it was successful
if (_queue.TryEnqueue(handler))
{
    // The handler was successfully enqueued
    Console.WriteLine("Handler enqueued successfully.");
}
else
{
    // The handler could not be enqueued, because
    // ShutdownQueueAsync() was called on the DispatcherQueueController
    // or the DispatcherQueue is no longer active.
    Console.WriteLine("Failed to enqueue handler.");
}

Applies to