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

# How to: Creating a thread pool task queue

> How to: Creating a thread pool task queue

## Example

The following example shows how to create a task queue that dispatches both work and completion callbacks on the system thread pool.

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

## Sample output

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

## See also

[Designing the task queue](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [How to: Creating a composite task queue](/build/core-features/common/async/async-task-queue-design-howto/creating-composite-task-queue.md)
- [How to: Creating a manual task queue](/build/core-features/common/async/async-task-queue-design-howto/creating-manual-task-queue.md)
- [Async task queue design](/build/core-features/common/async/async-task-queue-design.md)
- [XTaskQueueDispatchMode](/reference/system/xtaskqueue/enums/xtaskqueuedispatchmode.md)
- [How to: Using a task queue with a Windows message loop](/build/core-features/common/async/async-task-queue-design-howto/task-queue-windows-msg-loop.md)
