DispatcherQueueController.ShutdownQueueAsync 方法

定义

异步停止与此 DispatcherQueueController 关联的 DispatcherQueue,如果 DispatcherQueueController 是由 CreateOnDedicatedThread 创建的,则关闭线程。

此方法在启动关闭操作后立即返回异步操作 () ;但异步操作在关闭操作完成之前不会完成。

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

返回

异步操作,该操作将在队列调度其所有剩余工作后完成。

属性

示例

// 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);
        };
    }
}

注解

调用 ShutdownQueueAsync 时,将按以下顺序引发以下事件:

这些事件是 DispatcherQueue 对象的成员,其用途是通知侦听器 DispatcherQueue 正在关闭。 事件在运行 DispatcherQueue 事件循环本身的线程上引发。

适用于