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

# XAsyncOp

> 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](/reference/system/xasyncprovider/functions/xasyncbegin) is invoked.<br />If this operation code is implemented, the asynchronous provider should start their asynchronous work, by either calling [XAsyncSchedule](/reference/system/xasyncprovider/functions/xasyncschedule) or starting an external asynchronous process such as overlapped I/O.<br /> **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](/reference/system/xasyncprovider/functions/xasyncschedule) has been called to schedule work.<br />If this operation code is implemented, the asynchronous provider should perform their asynchronous work and then call [XAsyncComplete](/reference/system/xasyncprovider/functions/xasynccomplete), 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.<br />The values for the *buffer* and *bufferSize* fields of [XAsyncProviderData](/reference/system/xasyncprovider/structs/xasyncproviderdata) have been validated.                                                                                                                                                                                                                                                                                        |
| Cancel    | The asynchronous provider is invoked with this operation code when the asynchronous work should be canceled.<br />The asynchronous provider should cancel all asynchronous work and then call [XAsyncComplete](/reference/system/xasyncprovider/functions/xasynccomplete), 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](/reference/system/xasyncprovider/functions/xasyncprovider) 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](/build/core-features/common/async/async-programming-model#heading-7).

## Requirements

**Header:** XAsyncProvider.h

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

## See also

[XAsyncProviderData](/reference/system/xasyncprovider/structs/xasyncproviderdata)\
[XAsyncProvider Members](/reference/system/xasyncprovider/xasyncprovider_members)\
[Asynchronous Programming Model](/build/core-features/common/async/async-programming-model)
