Share via


DispatcherQueueController.ShutdownQueueAsync Metodo

Definizione

Arresta in modo asincrono dispatcherQueue associato a questo DispatcherQueueController e arresta il thread se DispatcherQueueController è stato creato da CreateOnDedicatedThread.

Questo metodo restituisce (un'operazione asincrona) non appena viene avviata l'operazione di arresto; ma l'operazione asincrona non viene completata fino al completamento dell'operazione di arresto.

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

Restituisce

Operazione asincrona, che verrà completata dopo che la coda ha inviato tutto il lavoro rimanente.

Attributi

Esempio

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

Commenti

Quando si chiama ShutdownQueueAsync, vengono generati gli eventi seguenti, in questo ordine:

Questi eventi sono membri dell'oggetto DispatcherQueue e il loro scopo è notificare ai listener che DispatcherQueue sta arrestando. Gli eventi vengono generati nel thread che esegue il ciclo di eventi DispatcherQueue stesso.

Si applica a