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

# XAsyncOp

> XAsyncOp

Represents an operation code for an asynchronous provider.

## Syntax

```cpp theme={null}
enum class XAsyncOp  : uint32_t  
{  
    Begin,  
    DoWork,  
    GetResult,  
    Cancel,  
    Cleanup  
}  
```

## Constants

| Constant | Description |
| - | - |
| Begin | The asynchronous provider is invoked with this operation code when [XAsyncBegin](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasyncbegin.md) is invoked. If this operation code is implemented, the asynchronous provider should start their asynchronous work, by either calling [XAsyncSchedule](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasyncschedule.md) or starting an external asynchronous process such as overlapped I/O.  **NOTE** Asynchronous work performed for this operation code must not block the thread. |
| DoWork | The asynchronous provider is invoked with this operation code when [XAsyncSchedule](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasyncschedule.md) has been called to schedule work. If this operation code is implemented, the asynchronous provider should perform their asynchronous work and then call [XAsyncComplete](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasynccomplete.md), specifying the data payload size in *requiredBufferSize*. If additional work needs to be done the asynchronous provider can schedule it and then call `XAsyncComplete`, specifying the error code E\_PENDING in *result*. |
| GetResult | The asynchronous provider is invoked with this operation code after an asynchronous call completes and the user needs to get the resulting data payload. The values for the *buffer* and *bufferSize* fields of [XAsyncProviderData](https://docs.xbox.com/reference/system/xasyncprovider/structs/xasyncproviderdata.md) have been validated. |
| Cancel | The asynchronous provider is invoked with this operation code when the asynchronous work should be canceled. The asynchronous provider should cancel all asynchronous work and then call [XAsyncComplete](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasynccomplete.md), specifying the error code E\_ABORT in *result*. |
| Cleanup | The asynchronous provider is invoked with this operation code when the asynchronous call is either completed or canceled and data in the context can be cleaned up. |

## Remarks

The [XAsyncProvider](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasyncprovider.md) callback function for an asynchronous provider is called repeatedly, and what that asynchronous provider should do for each call is determined by the operation code specified for each call. `XAsyncOp` represents the operation codes that can be implemented by an asynchronous provider.\
An asynchronous provider should implement only those operation codes from `XAsyncOp` needed to perform asynchronous work. For example, an asynchronous provider that performs non-cancelable asynchronous I/O work which doesn't require cleanup only needs to implement `XAsyncOp::GetResult`.

For an example of an asynchronous provider that implements the `DoWork`, `GetResult`, and `Cleanup` operation codes from `XAsyncOp`, see the "Async Library" section in [Asynchronous Programming Model](https://docs.xbox.com/build/core-features/common/async/async-programming-model.md#heading-7).

## Requirements

**Header:** XAsyncProvider.h

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## See also

[XAsyncProviderData](https://docs.xbox.com/reference/system/xasyncprovider/structs/xasyncproviderdata.md)\
[XAsyncProvider Members](https://docs.xbox.com/reference/system/xasyncprovider/xasyncprovider_members.md)\
[Asynchronous Programming Model](https://docs.xbox.com/build/core-features/common/async/async-programming-model.md)


## Related topics

- [XAsyncProvider](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasyncprovider.md)
- [XAsyncProviderData](https://docs.xbox.com/reference/system/xasyncprovider/structs/xasyncproviderdata.md)
- [XAsyncBegin](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasyncbegin.md)
- [XAsyncComplete](https://docs.xbox.com/reference/system/xasyncprovider/functions/xasynccomplete.md)
- [XAsyncProvider (API contents)](https://docs.xbox.com/reference/system/xasyncprovider/xasyncprovider_members.md)
