> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XAsync 库概述

> XAsync 库定义了每个异步任务所需的 XAsyncBlock 结构，以及用于启动调用、检查状态和取消任务的函数。

[XAsync](https://docs.xbox.com/zh-CN/reference/system/xasync/xasync_members.md) 库提供了用于定义异步任务及其回调的方法和数据。主要的异步原语 [XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md) 就是在此库中定义的。它是所有异步任务的必需项。

除了异步块之外，此库还提供了[启动基本异步调用](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasyncrun.md)、[获取异步任务状态](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasyncgetstatus.md)以及[尝试取消任务](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasynccancel.md)的方法。

## XAsyncBlock

[XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md) 是主要的异步原语，其中包含用于实现完成回调、向完成回调提供数据以及选择运行任务队列的成员。

异步块还包含系统内部用于运行时行为的私有数据。因此，此块不能在多个活动任务之间共享。系统使用这些数据在调用处于活动状态时标识异步调用。

```c++ theme={null}
struct XAsyncBlock
{
    /// <summary>
    /// The queue to queue the call on.
    /// </summary>
    XTaskQueueHandle queue;
    
    /// <summary>
    /// Optional context pointer to pass to the callback.
    /// </summary>
    void* context;
    
    /// <summary>
    /// Optional callback that is invoked when the call completes.
    /// </summary>
    XAsyncCompletionRoutine* callback;
    
    /// <summary>
    /// Internal use only.
    /// </summary>
    unsigned char internal[sizeof(void*) * 4];
};
```

## 参考 API 文档

* [XAsync (API 内容)](https://docs.xbox.com/zh-CN/reference/system/xasync/xasync_members.md)
  * 函数
    * [xasyncrun](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasyncrun.md)
    * [xasyncgetstatus](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasyncgetstatus.md)
    * [xasynccancel](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasynccancel.md)
  * 结构体
    * [XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md)

## 另请参阅

[设置异步任务](https://docs.xbox.com/zh-CN/build/core-features/common/async/async-libraries/async-library-xasync-example-setup-async-task.md)
[运行简单任务](https://docs.xbox.com/zh-CN/build/core-features/common/async/async-libraries/async-library-xasync-example-run-simple-task.md)
[运行 Microsoft Game Development Kit API 任务](https://docs.xbox.com/zh-CN/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task.md)
[XAsync 系统 API 内容](https://docs.xbox.com/zh-CN/reference/system/xasync/xasync_members.md)


## Related topics

- [XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md)
- [XAsync（API 内容）](https://docs.xbox.com/zh-CN/reference/system/xasync/xasync_members.md)
- [XAsyncCancel](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasynccancel.md)
- [XAsyncGetStatus](https://docs.xbox.com/zh-CN/reference/system/xasync/functions/xasyncgetstatus.md)
- [运行 Microsoft Game Development Kit (GDK) API 任务](https://docs.xbox.com/zh-CN/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task.md)
