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

# XTaskQueueSubmitCallback

> XTaskQueueSubmitCallback

# XTaskQueueSubmitCallback

Submits a callback to the queue for the given port.

## Syntax

```cpp theme={null}
HRESULT XTaskQueueSubmitCallback(  
         XTaskQueueHandle queue,  
         XTaskQueuePort port,  
         void* callbackContext,  
         XTaskQueueCallback* callback  
)  
```

### Parameters

*queue*   \_In\_\
Type: XTaskQueueHandle

The queue to submit the callback to.

*port*   \_In\_\
Type: [XTaskQueuePort](/reference/system/xtaskqueue/enums/xtaskqueueport)

The port to submit the callback to. Callbacks can be assigned to work or completion ports.

*callbackContext*   \_In\_opt\_\
Type: void\*

An optional context pointer that will be passed to the callback.

*callback*   \_In\_\
Type: [XTaskQueueCallback\*](/reference/system/xtaskqueue/functions/xtaskqueuecallback)

A pointer to the callback function.

### Return value

Type: HRESULT

HRESULT success or error code.

## Remarks

<img src="https://mintcdn.com/microsoft-4404708b/gzrdvT5kpqAXKEQt/images/gdk/reference/note.gif?s=6c1a4c009b25ad5315c45ce51bc83983" alt="alert" width="10" height="10" data-path="images/gdk/reference/note.gif" /> **Performance Note:**\
Adding an item to a queue needs to be lock and wait free in order to satisfy the performance requirements of upstream code. The following APIs are lock free:

* [XTaskQueueSubmitCallback](/reference/system/xtaskqueue/functions/xtaskqueuesubmitcallback)
* [XTaskQueueSubmitDelayedCallback](/reference/system/xtaskqueue/functions/xtaskqueuesubmitdelayedcallback)
* [XTaskQueueDispatch](/reference/system/xtaskqueue/functions/xtaskqueuedispatch), provided that 0 is passed for *timeoutInMs*

The following example demonstrates how a callback is submitted to either the work or completion port of a task queue. It first submits a work callback, and then at the end of the work callback it submits a completion callback, which will be typical.

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

## Requirements

**Header:** XTaskQueue.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## See also

[XTaskQueue members](/reference/system/xtaskqueue/xtaskqueue_members)\
[Asynchronous Programming Model](/build/core-features/common/async/async-programming-model)\
[Async Task Queue design](/build/core-features/common/async/async-task-queue-design)


## Related topics

- [XTaskQueueSubmitDelayedCallback](/reference/system/xtaskqueue/functions/xtaskqueuesubmitdelayedcallback.md)
- [XTaskQueueCallback](/reference/system/xtaskqueue/functions/xtaskqueuecallback.md)
- [XTaskQueueMonitorCallback](/reference/system/xtaskqueue/functions/xtaskqueuemonitorcallback.md)
- [XTaskQueuePort](/reference/system/xtaskqueue/enums/xtaskqueueport.md)
- [XTaskQueueCreate](/reference/system/xtaskqueue/functions/xtaskqueuecreate.md)
