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

# XAsync 库概述

> XAsync 库概述

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

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

<a id="xasyncblock" />

## XAsyncBlock

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

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

```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 内容)](/reference/system/xasync/xasync_members)
  * 函数
    * [xasyncrun](/reference/system/xasync/functions/xasyncrun)
    * [xasyncgetstatus](/reference/system/xasync/functions/xasyncgetstatus)
    * [xasynccancel](/reference/system/xasync/functions/xasynccancel)
  * 结构体
    * [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)

## 另请参阅

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


## Related topics

- [XAsync](/zh-CN/reference/system/xasync/xasync_members.md)
- [XAsyncBlock](/zh-CN/reference/system/xasync/structs/xasyncblock.md)
- [XAsyncCancel](/zh-CN/reference/system/xasync/functions/xasynccancel.md)
- [XAsyncGetStatus](/zh-CN/reference/system/xasync/functions/xasyncgetstatus.md)
- [XAsyncRun](/zh-CN/reference/system/xasync/functions/xasyncrun.md)
