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

# XAsyncComplete

> XAsyncComplete

# XAsyncComplete

表示非同步提供者的回呼函式已完成工作，且可以傳回結果。

## 語法

```cpp theme={null}
void XAsyncComplete(  
         XAsyncBlock* asyncBlock,  
         HRESULT result,  
         size_t requiredBufferSize  
)  
```

### 參數

*asyncBlock*   \_Inout\_\
類型：[XAsyncBlock\*](/zh-TW/reference/system/xasync/structs/xasyncblock)

指向傳遞給 [XAsyncBegin](/zh-TW/reference/system/xasyncprovider/functions/xasyncbegin) 之 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock) 的指標。

*result*   \_In\_\
類型：[HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

回呼函式所執行工作的結果。如果工作已取消，請將此值設定為 `E_ABORT`。如果需要完成更多工作，請將此值設定為 `E_PENDING`。否則，請將此值設定為適當的結果碼。

*requiredBufferSize*   \_In\_\
類型：size\_t

回呼函式要傳回之資料承載所需的大小 (以位元組為單位)。如果回呼函式不會傳回資料承載，請將此值設定為零。如果回呼函式傳回錯誤，則會忽略此參數。

### 傳回值

類型：void

## 備註

<Note>在時間敏感執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

當回呼函式已被呼叫以執行或取消非同步工作時，會呼叫此函式。此函式會傳回適當的結果碼，以及資料承載的相關資訊 (如果適用)。回呼函式的 [XAsyncOp](/zh-TW/reference/system/xasyncprovider/enums/xasyncop) 作業代碼、非同步工作及資料承載的組合，通常會決定呼叫此函式時應為 *result* 和 *requiredBufferSize* 提供的值。

如果回呼函式是以 `XAsyncOp::DoWork` 作業代碼呼叫，回呼函式應執行非同步工作。如果回呼函式已完成所有非同步工作，請將 *result* 設定為適當的錯誤碼。如果需要完成更多工作，請將 *result* 設定為 `E_PENDING`。如果函式會傳回資料承載，請將 *requiredBufferSize* 設定為傳回資料承載所需之緩衝區的大小 (以位元組為單位)；否則，請將 *requiredBufferSize* 設定為零。

如果回呼函式是以 `XAsyncOp::Cancel` 作業代碼呼叫，回呼函式應取消非同步工作。請將 *result* 設定為 `E_ABORT`，並將 *requiredBufferSize* 設定為零。

## 需求

**標頭：** XAsyncProvider.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [設定可取消性](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-cancelability)
* [設定自訂提供者](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-custom-provider)
* [設定傳回資料](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-return-data)
* [非同步程式設計模型](/zh-TW/build/core-features/common/async/async-programming-model)
* [時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[XAsyncProvider 成員](/zh-TW/reference/system/xasyncprovider/xasyncprovider_members)\
[XAsyncBegin](/zh-TW/reference/system/xasyncprovider/functions/xasyncbegin)\
[非同步程式設計模型](/zh-TW/build/core-features/common/async/async-programming-model)


## Related topics

- [XAsyncComplete](/reference/system/xasyncprovider/functions/xasynccomplete.md)
- [XAsyncOp](/reference/system/xasyncprovider/enums/xasyncop.md)
- [XAsyncGetResult](/reference/system/xasyncprovider/functions/xasyncgetresult.md)
- [AsyncProviderData](/reference/system/xasyncprovider/structs/xasyncproviderdata.md)
