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

# XAsyncRun

> XAsyncRun

# XAsyncRun

以非同步方式執行指定的回呼函式。

## 語法

```cpp theme={null}
HRESULT XAsyncRun(  
         XAsyncBlock* asyncBlock,  
         XAsyncWork* work  
)  
```

### 參數

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

指向用來追蹤非同步呼叫之 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock) 的指標。

*work*   \_In\_\
類型：[XAsyncWork\*](/zh-TW/reference/system/xasync/functions/xasyncwork)

指向要以非同步方式執行之回呼函式的指標。

### 傳回值

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

如果成功，則傳回 `S_OK`；否則傳回錯誤碼。如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。

## 備註

`XAsyncRun` 是一個協助程式函式，會以非同步方式執行 *work* 中指定的回呼函式。您可以使用 *asyncBlock* 中指定的 `XAsyncBlock` 來取消回呼函式或取得其狀態。`XAsyncRun` 在內部使用下列 `XAsyncProvider` 函式來執行和追蹤回呼函式：

* [XAsyncBegin](/zh-TW/reference/system/xasyncprovider/functions/xasyncbegin)
* [XAsyncComplete](/zh-TW/reference/system/xasyncprovider/functions/xasynccomplete)
* [XAsyncSchedule](/zh-TW/reference/system/xasyncprovider/functions/xasyncschedule)

如需使用 `XAsyncProvider` 和 `XAsyncBlock` 實作您自己的非同步功能的詳細資訊，請參閱[非同步程式設計模型](/zh-TW/build/core-features/common/async/async-programming-model)。

## 需求

**標頭：** XAsync.h

**程式庫：** xgameruntime.lib

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

## 概念文件

* [執行 Microsoft Game Development Kit (GDK) API 工作](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task)
* [執行簡單工作](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasync-example-run-simple-task)
* [XAsync 程式庫概觀](/zh-TW/build/core-features/common/async/async-libraries/async-library-xasync)
* [設定可取消性](/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-programming-model)
* [泛型非同步工作包裝函式](/zh-TW/build/core-features/common/async/async-task-function-example)

## 另請參閱

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


## Related topics

- [XAsyncRun](/reference/system/xasync/functions/xasyncrun.md)
- [Run simple task example](/build/core-features/common/async/async-libraries/async-library-xasync-example-run-simple-task.md)
- [XAsyncWork](/reference/system/xasync/functions/xasyncwork.md)
- [XAsync](/reference/system/xasync/xasync_members.md)
