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

> The XAsync library defines the XAsyncBlock structure required by every async task, along with functions to start calls, check status, and cancel tasks.

The [XAsync](https://docs.xbox.com/reference/system/xasync/xasync_members.md) library provides methods and data that define async tasks and their callbacks. The main async primitive, [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md), is defined in this library. It's a
requirement for all async tasks.

Beyond the async block, this library provides methods to [start basic async calls](https://docs.xbox.com/reference/system/xasync/functions/xasyncrun.md), [get async task status](https://docs.xbox.com/reference/system/xasync/functions/xasyncgetstatus.md), and [attempt to cancel tasks](https://docs.xbox.com/reference/system/xasync/functions/xasynccancel.md).

## XAsyncBlock

The [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md) is the main async primitive that contains members that are used for implementing the completion callback, providing data to the completion callback, and choosing a task queue to run in.

The async block also contains private data that's used internally by the system for runtime behavior. As a result, this block can't be shared between multiple active tasks. The system uses this data to identify the async call while the call is active.

```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];
};
```

## Reference API documentation

* [XAsync (API contents)](https://docs.xbox.com/reference/system/xasync/xasync_members.md)
  * Functions
    * [xasyncrun](https://docs.xbox.com/reference/system/xasync/functions/xasyncrun.md)
    * [xasyncgetstatus](https://docs.xbox.com/reference/system/xasync/functions/xasyncgetstatus.md)
    * [xasynccancel](https://docs.xbox.com/reference/system/xasync/functions/xasynccancel.md)
  * Structures
    * [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md)

## See also

[Setup async task](https://docs.xbox.com/build/core-features/common/async/async-libraries/async-library-xasync-example-setup-async-task.md)
[Run simple task](https://docs.xbox.com/build/core-features/common/async/async-libraries/async-library-xasync-example-run-simple-task.md)
[Run Microsoft Game Development Kit API task](https://docs.xbox.com/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task.md)
[XAsync system API contents](https://docs.xbox.com/reference/system/xasync/xasync_members.md)


## Related topics

- [XAsync (API contents)](https://docs.xbox.com/reference/system/xasync/xasync_members.md)
- [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md)
- [Set up async task](https://docs.xbox.com/build/core-features/common/async/async-libraries/async-library-xasync-example-setup-async-task.md)
- [XAsyncCancel](https://docs.xbox.com/reference/system/xasync/functions/xasynccancel.md)
- [XAsyncRun](https://docs.xbox.com/reference/system/xasync/functions/xasyncrun.md)
