DispatcherQueueController.ShutdownQueueAsync 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
以非同步方式停止與此DispatcherQueueController 相關聯的 DispatcherQueueController,如果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 事件迴圈本身的執行緒上會引發事件。