DispatcherQueueController.ShutdownQueueAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public:
virtual IAsyncAction ^ ShutdownQueueAsync() = ShutdownQueueAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncAction ShutdownQueueAsync();
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncAction ShutdownQueueAsync();
function shutdownQueueAsync()
Public Function ShutdownQueueAsync () As IAsyncAction
Returns
An asynchronous operation, which will complete after the queue has dispatched all of its remaining work.
- Attributes
Examples
// 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.
_queue.TryEnqueue(
() =>
{
FinalInThreadCleanup(_myState);
});
};
// Invoked after the DispatcherQueue event loop exits.
_dispatcherQueue.ShutdownCompleted += (s, e) =>
{
CleanUp(_myState);
};
}
}
Remarks
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.