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

# XAsyncBegin

> XAsyncBegin

# XAsyncBegin

Initializes an [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) and begins asynchronous work by an asynchronous provider.

## Syntax

```cpp theme={null}
HRESULT XAsyncBegin(  
         XAsyncBlock* asyncBlock,  
         void* context,  
         const void* identity,  
         const char* identityName,  
         XAsyncProvider* provider  
)  
```

### Parameters

*asyncBlock*   \_Inout\_\
Type: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

A pointer to the [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) that holds data for the asynchronous call.

*context*   \_In\_opt\_\
Type: void\*

Optional. A context pointer to be stored in the [XAsyncProviderData](/reference/system/xasyncprovider/structs/xasyncproviderdata) object passed to the [XAsyncProvider](/reference/system/xasyncprovider/functions/xasyncprovider) callback function.

*identity*   \_In\_opt\_\
Type: void\*

Optional. A pointer to an arbitrary token that can be used to identify the asynchronous call.

*identityName*   \_In\_opt\_\
Type: char\*

Optional. An string that names the function providing the asynchronous call. The value of this parameter is typically set to the `__FUNCTION__` compiler macro.

*provider*   \_In\_\
Type: [XAsyncProvider](/reference/system/xasyncprovider/functions/xasyncprovider)\*

A pointer to the [XAsyncProvider](/reference/system/xasyncprovider/functions/xasyncprovider) callback function to invoke for the asynchronous call.

### Return value

Type: [HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

Returns `S_OK` if successful; otherwise, returns an error code. For a list of error codes, see [Error Codes](/reference/errorcodes).

## Remarks

`XAsyncBegin` is invoked to indicate that the asynchronous provider should begin asynchronous work. After `XAsyncBegin` is invoked, other [XAsyncProvider](/reference/system/xasyncprovider/xasyncprovider_members) functions, such as [XAsyncGetResult](/reference/system/xasyncprovider/functions/xasyncgetresult) will provide meaningful data.

When `XAsyncBegin` is invoked, the callback function specified in *provider* is invoked, specifying [XAsyncOp::Begin](/reference/system/xasyncprovider/enums/xasyncop) in the *op* parameter of [XAsyncProvider](/reference/system/xasyncprovider/functions/xasyncprovider). If the callback function implements this operation code, it should start its asynchronous work by either calling [XAsyncSchedule](/reference/system/xasyncprovider/functions/xasyncschedule) or through exterior means. After `XAsyncBegin` returns, it is assumed that the callback function has started asynchronous work on a system-defined thread.

<Note>The callback function specified in *provider* is processed synchronously in the `XAsyncBegin` call chain. Asynchronous work performed by the callback function must not block the thread.</Note>

You can use the *identity* and *identityName* parameters to identify and manage mismatched `XAsyncOp::Begin` and `XAsyncOp::GetResult` calls to the callback function. Typically, the value of *identity* is set to the function pointer of the function that invoked `XAsyncBegin`, and the value of *identityName* is set to the `__FUNCTION__` compiler macro.

## Requirements

**Header:** XAsyncProvider.h

**Library:** xgameruntime.lib

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

## Conceptual documentation

* [Set up custom provider](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-custom-provider)
* [XAsyncProvider library overview](/build/core-features/common/async/async-libraries/async-library-xasyncprovider)
* [Asynchronous Programming Model](/build/core-features/common/async/async-programming-model)

## See also

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


## Related topics

- [XAsyncComplete](/reference/system/xasyncprovider/functions/xasynccomplete.md)
- [XAsyncSchedule](/reference/system/xasyncprovider/functions/xasyncschedule.md)
- [XAsyncGetResult](/reference/system/xasyncprovider/functions/xasyncgetresult.md)
- [AsyncProviderData](/reference/system/xasyncprovider/structs/xasyncproviderdata.md)
- [XAsyncProvider library overview](/build/core-features/common/async/async-libraries/async-library-xasyncprovider.md)
