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

# 操作說明：提交回呼

> 操作說明：提交回呼

## 範例

下列範例示範如何將回呼提交至工作佇列的工作連接埠
或完成連接埠。首先，它會提交工作回呼。接著，在工作回呼結束時，它會提交完成回呼。這是典型的用法。為求簡潔，
後續案例都會使用 `SubmitCallbacks` 函式。

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

## 另請參閱

[設計工作佇列](/zh-TW/build/core-features/common/async/async-task-queue-design)


## Related topics

- [如何：提交回调](/zh-CN/build/core-features/common/async/async-task-queue-design-howto/submitting-callbacks.md)
- [XTaskQueuePort](/zh-CN/reference/system/xtaskqueue/enums/xtaskqueueport.md)
- [XTaskQueueRegisterMonitor](/zh-CN/reference/system/xtaskqueue/functions/xtaskqueueregistermonitor.md)
- [XTaskQueueSubmitCallback](/zh-CN/reference/system/xtaskqueue/functions/xtaskqueuesubmitcallback.md)
- [XTaskQueueSubmitDelayedCallback](/zh-CN/reference/system/xtaskqueue/functions/xtaskqueuesubmitdelayedcallback.md)
