Share via


DispatcherQueueController.ShutdownQueueAsync メソッド

定義

この DispatcherQueueController に関連付けられている DispatcherQueue を非同期的に停止し、DispatcherQueueControllerCreateOnDedicatedThread によって作成された場合にスレッドをシャットダウンします。

このメソッドは、シャットダウン操作が開始されるとすぐに (非同期操作) を返します。ただし、シャットダウン操作が完了するまで非同期操作は完了しません。

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 イベント ループ自体を実行しているスレッドで発生します。

適用対象