> ## 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: Submitting callbacks

> How to: Submitting callbacks

## Example

The following example shows how to submit a callback to either the work port
or the completion port of a task queue. First, it submits a work callback. Then, at the end of the work callback, it submits a completion callback. This is typical usage. The `SubmitCallbacks` function is
used in subsequent scenarios for brevity.

```c++ theme={null}
void CALLBACK SampleCompletionCallback(void*, bool cancel)
{
    printf("Completion invoked on thread %d. Cancel? %d.\r\n",
    GetCurrentThreadId(), cancel);
}

void CALLBACK SampleWorkCallback(void* context, bool cancel)
{
    printf("Worker invoked on thread %d. Cancel? %d.\r\n",
    GetCurrentThreadId(), cancel);

    XTaskQueueHandle queueFromContext = static_cast<XTaskQueueHandle>(context);

    HRESULT hrCompletion = XTaskQueueSubmitCallback(
        queueFromContext,
        XTaskQueuePort::Completion,
        nullptr,
        SampleCompletionCallback);

    if (FAILED(hrCompletion))
    {
        printf("Error 0x%x submitting completion.\r\n", hrCompletion);
    }
}

void SubmitCallbacks(XTaskQueueHandle queue)
{
    HRESULT hrWork = XTaskQueueSubmitCallback(
        queue,
        XTaskQueuePort::Work,
        queue,
        SampleWorkCallback);

    if (FAILED(hrWork))
    {
        printf("Error 0x%x submitting work.\r\n", hrWork);
    }
}
```

## See also

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


## Related topics

- [How to: Using delayed callbacks](/build/core-features/common/async/async-task-queue-design-howto/using-delayed-callbacks.md)
- [How to](/services/xbox-services/community/reputation/how-to/index.md)
- [Async task queue design](/build/core-features/common/async/async-task-queue-design.md)
- [How to configure a hidden pre-order](/publishing/game-publishing/how-to/how-to-create-preorder-hidden-products.md)
- [How to configure a Game or Durable pre-order](/publishing/game-publishing/how-to/how-to-create-preorder-visible-product.md)
