DispatcherQueueController DispatcherQueueController DispatcherQueueController DispatcherQueueController Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Manages the lifetime of a DispatcherQueue. Provides methods to create and shutdown the DispatcherQueue.

public : sealed class DispatcherQueueController : IDispatcherQueueControllerpublic sealed class DispatcherQueueController : IDispatcherQueueControllerPublic NotInheritable Class DispatcherQueueController Implements IDispatcherQueueController// This API is not available in Javascript.
Attributes
Windows 10 requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Remarks

Object and Thread Lifetime

DispatcherQueueController and its associated DispatcherQueue will be kept alive while the event loop is running. When Shutdown is completed, the loop is terminated and the dedicated thread will unwind. However, DispacherQueueController and the associated DispatcherQueue object can outlive thread’s lifetime and will be disposed when all their references are released.

Properties

DispatcherQueue DispatcherQueue DispatcherQueue DispatcherQueue

Prerelease. Gets the DispatcherQueue associated with this DispatcherQueueController.

public : DispatcherQueue DispatcherQueue { get; }public DispatcherQueue DispatcherQueue { get; }Public ReadOnly Property DispatcherQueue As DispatcherQueue// This API is not available in Javascript.
Value
DispatcherQueue DispatcherQueue DispatcherQueue DispatcherQueue

The DispatcherQueue instance that you use to queue tasks that run on a thread.

Methods

CreateOnDedicatedThread() CreateOnDedicatedThread() CreateOnDedicatedThread() CreateOnDedicatedThread()

Prerelease. Creates a DispatcherQueue that you can use to run tasks on a dedicated thread.

public : static DispatcherQueueController CreateOnDedicatedThread()public static DispatcherQueueController CreateOnDedicatedThread()Public Static Function CreateOnDedicatedThread() As DispatcherQueueController// This API is not available in Javascript.
Returns

Remarks

You can access the created DispatcherQueue via DispatcherQueueController.DispatcherQueue.

ShutdownQueueAsync() ShutdownQueueAsync() ShutdownQueueAsync() ShutdownQueueAsync()

Prerelease. Stops the DispatcherQueue associated with this DispatcherQueueController. Shuts down the thread if the DispatcherQueueController was created by CreateOnDedicatedThread.

public : IAsyncAction ShutdownQueueAsync()public IAsyncAction ShutdownQueueAsync()Public Function ShutdownQueueAsync() As IAsyncAction// This API is not available in Javascript.
Returns

An asynchronous operation which will complete after the queue has dispatched all of its remaining work.

Examples

// Shutdown the event loop
public async void ShutdownLoop()
{

    if (_queueController != null)

    {

        // The await will complete after the event loop exits

        await _queueController.ShutdownQueueAsync();

        _queueController = null;

        _queue = null;

    }

}


// Another class that has access to the dedicated thread’s DispatcherQueue.
public class ModuleA
{

    public async void ShutdownSetup()

    {

        // Gets the DispatcherQueue for the dedicated thread



        // Invoked when controller begins the ShutdownQueueAsync.

        _dispatcherQueue.ShutdownStarting += (s, e) =>

        {

            // Queue is shutting down, do this last operation which

            // will update state before the loop exits

            _queue.TryEnqueue(

                () =>

                {

                    FinalInThreadCleanup(_myState);

                });

        };



        // Invoked after the DispatcherQueue event loop exits.

        _dispatcherQueue.ShutdownCompleted += (s, e) =>

        {

            CleanUp(_myState);

        };

    }

}

Remarks

After ShutdownQueueAsync fires, two events (DispatcherQueue.ShutdownStarting and DispatcherQueue.ShutdownCompleted ) fire on the DispatcherQueue to notify listeners that the DispatcherQueue is shutting down. The events are fired on the thread running the DispatcherQueue event loop itself.

DispatcherQueue.ShutdownStarting fires before the event loop exits. The event handler can take a deferral and continue to post work until the deferral completes. Once the deferral completes, the DispatcherQueue will no longer accept work and DispatcherQueue.TryEnqueue will return false.
DispatcherQueue.ShutdownCompleted will fire after the event loop has been exited. This event can be used to clean up any state maintained by partner components that were maintained on the dedicated thread.