DispatcherQueueController.ShutdownQueueAsync Method


Asynchronously stops the DispatcherQueue associated with this DispatcherQueueController, and shuts down the thread if the DispatcherQueueController was created by CreateOnDedicatedThread.

This method returns (an asynchronous operation) as soon as the shutdown operation is started; but the asynchronous operation doesn't complete until the shutdown operation is complete.

 virtual IAsyncAction ^ ShutdownQueueAsync() = ShutdownQueueAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncAction ShutdownQueueAsync();
public IAsyncAction ShutdownQueueAsync();
function shutdownQueueAsync()
Public Function ShutdownQueueAsync () As IAsyncAction


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



// Shut down 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 the controller begins the ShutdownQueueAsync.
        _dispatcherQueue.ShutdownStarting += (s, e) =>
            // Queue is shutting down, do this last operation which
            // will update state before the loop exits.
                () =>

        // Invoked after the DispatcherQueue event loop exits.
        _dispatcherQueue.ShutdownCompleted += (s, e) =>


When you call ShutdownQueueAsync, the following events are raised, in this order:

Those events are members of the DispatcherQueue object, and their purpose is to notify listeners that the DispatcherQueue is shutting down. The events are raised on the thread running the DispatcherQueue event loop itself.

Applies to