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

# Como: criar uma fila de tarefas manual

> Exemplo que cria uma fila de tarefas no modo de despacho Manual e executa dois threads STL que chamam XTaskQueueDispatch para a porta de trabalho e a porta de conclusão.

## Exemplo

Talvez você queira controlar explicitamente os threads usados para o trabalho e as conclusões da fila de tarefas. Nesses
casos, crie uma *fila de tarefas manual* e despache as chamadas você mesmo. Se você estiver usando filas de tarefas manuais,
deverá garantir que elas também bombeiem a fila de mensagens do Windows.

O exemplo a seguir mostra como criar uma fila de tarefas bombeada manualmente. Ele cria dois threads
STL que despacham chamadas tanto para a porta de trabalho quanto para a porta de conclusão.

```c++ theme={null}
void CreatingTaskQueueWithManualThreads() 
{  
    // Create a manual task queue.  
    XTaskQueueHandle queue;  
  
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::Manual,  
        XTaskQueueDispatchMode::Manual,  
        &queue);  
  
    if (FAILED(hr))  
    {  
        printf("Creating queue failed: 0x%x\r\n", hr);  
        return;  
    }  
  
    // We create threads to pump the queue: one thread for the work port  
    // and one thread for the completion port.  
    std::thread workThread([queue]  
    {  
        // XTaskQueueDispatch returns false when there's nothing to  
        // dispatch. Here, we wait forever for something new to come  
        // in. This will return false only if the queue is being  
        // terminated.  
        while (XTaskQueueDispatch(queue, XTaskQueuePort::Work, INFINITE));  
    });  
  
    std::thread completionThread([queue]  
    {  
        // XTaskQueueDispatch returns false when there's nothing to  
        // dispatch. Here, we wait forever for something new to come  
        // in. This will return false only if the queue is being  
        // terminated.  
        while (XTaskQueueDispatch(queue, XTaskQueuePort::Completion, INFINITE));  
    });  
  
    SubmitCallbacks(queue);  
  
    // Wait a while for the callbacks to run.  
    Sleep(1000);  
  
    // Terminating the queue will cause a waiting XTaskQueueDispatch to return  
    // false.  
    XTaskQueueTerminate(queue, true, nullptr, nullptr);  
  
    workThread.join();  
    completionThread.join();  
}  
```

## Consulte também

[Projetando a fila de tarefas](https://docs.xbox.com/pt-BR/build/core-features/common/async/async-task-queue-design.md)


## Related topics

- [Como: Criar uma fila de tarefas composta](https://docs.xbox.com/pt-BR/build/core-features/common/async/async-task-queue-design-howto/creating-composite-task-queue.md)
- [Como: criar uma fila de tarefas de pool de threads](https://docs.xbox.com/pt-BR/build/core-features/common/async/async-task-queue-design-howto/creating-thread-pool-task-queue.md)
- [Como: usar uma fila de tarefas com um loop de mensagens do Windows](https://docs.xbox.com/pt-BR/build/core-features/common/async/async-task-queue-design-howto/task-queue-windows-msg-loop.md)
- [Como: usar um waiter de fila de tarefas](https://docs.xbox.com/pt-BR/build/core-features/common/async/async-task-queue-design-howto/using-task-queue-waiter.md)
- [Como: usar a fila de tarefas do processo](https://docs.xbox.com/pt-BR/build/core-features/common/async/async-task-queue-design-howto/using-process-task-queue.md)
