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

异步运行指定的回调函数。

## Syntax

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

### Parameters

*asyncBlock*   \_Inout\_\
类型：[XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

指向用于跟踪异步调用的 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) 的指针。

*work*   \_In\_\
类型：[XAsyncWork\*](/reference/system/xasync/functions/xasyncwork)

指向要异步运行的回调函数的指针。

### Return value

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

成功时返回 `S_OK`；否则，返回错误代码。有关错误代码列表，请参阅[错误代码](/reference/errorcodes)。

## Remarks

`XAsyncRun` 是一个帮助程序函数，它异步运行 *work* 中指定的回调函数。可以使用 *asyncBlock* 中指定的 `XAsyncBlock` 来取消或获取回调函数的状态。`XAsyncRun` 在内部使用以下 `XAsyncProvider` 函数来运行和跟踪回调函数：

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

有关使用 `XAsyncProvider` 和 `XAsyncBlock` 实现自己的异步功能的详细信息，请参阅[异步编程模型](/build/core-features/common/async/async-programming-model)。

## Requirements

**头文件：** XAsync.h

**库：** xgameruntime.lib

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## Conceptual documentation

* [运行 Microsoft 游戏开发工具包 (GDK) API 任务](/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task)
* [运行简单任务](/build/core-features/common/async/async-libraries/async-library-xasync-example-run-simple-task)
* [XAsync 库概述](/build/core-features/common/async/async-libraries/async-library-xasync)
* [设置可取消性](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-cancelability)
* [设置自定义提供程序](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-custom-provider)
* [异步编程模型](/build/core-features/common/async/async-programming-model)
* [通用异步任务包装器](/build/core-features/common/async/async-task-function-example)

## See also

[XAsync Members](/reference/system/xasync/xasync_members)\
[XAsyncProvider Members](/reference/system/xasyncprovider/xasyncprovider_members)\
[异步编程模型](/build/core-features/common/async/async-programming-model)


## Related topics

- [XAsyncWork](/zh-CN/reference/system/xasync/functions/xasyncwork.md)
- [XAsync](/zh-CN/reference/system/xasync/xasync_members.md)
- [运行简单任务示例](/zh-CN/build/core-features/common/async/async-libraries/async-library-xasync-example-run-simple-task.md)
- [XNetworkingQueryPreferredLocalUdpMultiplayerPortAsync](/zh-CN/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerportasync.md)
- [通用异步任务包装器](/zh-CN/build/core-features/common/async/async-task-function-example.md)
