Share via


DispatcherQueueController.ShutdownQueueAsync Metode

Definisi

Secara asinkron menghentikan DispatcherQueue yang terkait dengan DispatcherQueueController ini, dan mematikan utas jika DispatcherQueueController dibuat oleh CreateOnDedicatedThread.

Metode ini mengembalikan (operasi asinkron) segera setelah operasi pematian dimulai; tetapi operasi asinkron tidak selesai sampai operasi pematian selesai.

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

Mengembalikan

Operasi asinkron, yang akan selesai setelah antrean mengirimkan semua pekerjaan yang tersisa.

Atribut

Contoh

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

Keterangan

Saat Anda memanggil ShutdownQueueAsync, peristiwa berikut dinaikkan, dalam urutan ini:

Peristiwa tersebut adalah anggota objek DispatcherQueue , dan tujuannya adalah untuk memberi tahu pendengar bahwa DispatcherQueue dimatikan. Peristiwa dinaikkan pada utas yang menjalankan perulangan peristiwa DispatcherQueue itu sendiri.

Berlaku untuk