> ## 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.

# 如何：创建线程池任务队列

> 如何：创建线程池任务队列

## 示例

以下示例展示了如何创建一个在系统线程池上分派工作和完成回调的任务队列。

```c++ theme={null}
void CreatingTaskQueue()  
{  
    XTaskQueueHandle queue;  
 
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::ThreadPool,  
        XTaskQueueDispatchMode::ThreadPool,  
        &queue);  
 
    if (FAILED(hr))  
    { 
        printf("Creating queue failed: 0x%x\r\n", hr);  
        return;  
    }  
 
    SubmitCallbacks(queue); 
 
    // Wait a while for the callbacks to run.  
    Sleep(1000);  
 
    XTaskQueueTerminate(queue, true, nullptr, nullptr);  
}  
```

## 示例输出

```
Worker invoked on thread 11440. Cancel? 0. 
Completion invoked on thread 11440. Cancel? 0.  
```

## 另请参阅

[设计任务队列](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [如何：创建复合任务队列](/zh-CN/build/core-features/common/async/async-task-queue-design-howto/creating-composite-task-queue.md)
- [如何：创建手动任务队列](/zh-CN/build/core-features/common/async/async-task-queue-design-howto/creating-manual-task-queue.md)
- [异步任务队列设计](/zh-CN/build/core-features/common/async/async-task-queue-design.md)
- [XTaskQueueDispatchMode](/zh-CN/reference/system/xtaskqueue/enums/xtaskqueuedispatchmode.md)
- [如何：将任务队列与 Windows 消息循环结合使用](/zh-CN/build/core-features/common/async/async-task-queue-design-howto/task-queue-windows-msg-loop.md)
