> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 方法: 複合タスク キューの作成

> 方法: 複合タスク キューの作成

## 例

*複合タスク キュー* は、他のキューの部品から構成されたタスク キューです。複合タスク キューは、ある非同期タスクが別のタスクを呼び出す必要があり、そのタスクの完了が完了スレッドのサイクルを浪費するべきでない中間ステップである場合に便利です。この場合、複合キューを作成できます。この複合キューのワーク ポートと完了ポートは、両方とも元のキューのワーク ポートを使用します。

次の例では、作業にはスレッド プールを使用しながら、完了ポート コールバックを Win32 の WindowProc コールバック関数に統合しています。この例では、他のスレッド モデルと統合する際のタスク キューの正しい終了方法も示しています。

```c++ theme={null}
void CreatingCompositeQueue()  
{  
    XTaskQueueHandle queue;  
  
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::ThreadPool,  
        XTaskQueueDispatchMode::Manual,  
        &queue);  
  
    if (FAILED(hr))  
    {  
        printf("Failed to create task queue: 0x%x\r\n", hr);  
        return;  
    }  
  
    XTaskQueuePortHandle workPort;  
  
    // Create a composite queue that uses the work port from  
    // another queue for both the work and the completion ports.  
  
    hr = XTaskQueueGetPort(queue, XTaskQueuePort::Work, &workPort);  
    if (FAILED(hr))  
    {  
        printf("Failed to get work port 0x%x\r\n", hr);  
        XTaskQueueCloseHandle(queue);  
        return;  
    }  
  
    XTaskQueueHandle compositeQueue;  
    hr = XTaskQueueCreateComposite(workPort, workPort, &compositeQueue);  
    if (FAILED(hr))  
    {  
        printf("Failed to create composite queue 0x%x\r\n", hr);  
        XTaskQueueCloseHandle(queue);  
        return;  
    }  
  
    // Use the queue as needed.  
    SubmitCallbacks(compositeQueue);  
  
    // Wait a while for the callbacks to run.  
    Sleep(1000);  
  
    XTaskQueueCloseHandle(compositeQueue);  
    XTaskQueueCloseHandle(queue);  
}  
```

もう 1 つの手法は、ワークと完了のディスパッチ タイプが *即時* のローカル キューを作成することです。即時ディスパッチ モードは、非同期の動作を一切伴いません。次のコード例に示すように、コールバックが送信されるとすぐにディスパッチします。

```c++ theme={null}
void CreatingImmediateQueue()  
{  
    XTaskQueueHandle queue;  
  
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::Immediate,  
        XTaskQueueDispatchMode::Immediate,  
        &queue);  
  
    if (FAILED(hr))  
    {  
        printf("Failed to create task queue: 0x%x\r\n", hr);  
        return;  
    }  
  
    // Use the queue as needed.  
    SubmitCallbacks(queue);  
  
    // Wait a while for the callbacks to run.  
    Sleep(1000);  
  
    XTaskQueueCloseHandle(queue);  
}  
```

## 関連項目

[タスク キューの設計](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [方法: 手動タスク キューの作成](/ja-jp/build/core-features/common/async/async-task-queue-design-howto/creating-manual-task-queue.md)
- [方法: スレッド プール タスク キューの作成](/ja-jp/build/core-features/common/async/async-task-queue-design-howto/creating-thread-pool-task-queue.md)
- [非同期タスク キューの設計](/ja-jp/build/core-features/common/async/async-task-queue-design.md)
- [タスク キューの作成例](/ja-jp/build/core-features/common/async/async-libraries/async-library-xtaskqueue-example-create-task-queue.md)
- [方法: タスク キュー ウェイターの使用](/ja-jp/build/core-features/common/async/async-task-queue-design-howto/using-task-queue-waiter.md)
