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

# Run simple task example

> Run simple task example

This topic provides an example of how to run a simple user task. Simple tasks can be started with the [XAsyncRun](/reference/system/xasync/functions/xasyncrun) function.
This function takes the async block as an input and then requires
implementing the work callback as a functor or lambda input. Remember
that the async block specifies the task queue to use and the optional
completion callback.

```c++ theme={null}
XAsyncBlock* async = new XAsyncBlock{};
async->queue = taskQueue;
async->context = contextData;
async->callback = 
    [](XAsyncBlock* async)
    {
        // The optional completion callback.
        delete async;
    }

XAsyncRun(async,
    [](XAsyncBlock* async)->HRESULT
    {
        // The work callback is implemented here.
        return S_OK;
    });
```

This example uses `XAsyncRun`to start a custom, simple
asynchronous task. The async block contains the task queue to use and
the completion callback.
`XAsyncRun` requires a work callback, and
it has a return value. It's returned from a call to
[XAsyncGetStatus](/reference/system/xasync/functions/xasyncgetstatus) afterward. Internally, `XAsyncRun`
has a simple async provider setup to handle the enqueuing of the
specified work callback, the enqueuing of the completion callback in the
async block, and other state changes for the process. This means that no
further code is needed for running simple async tasks - just set up the
async block and call `XAsyncRun`.

## Reference API documentation

* [XAsync (API contents)](/reference/system/xasync/xasync_members)
  * Functions
    * [XAsyncRun](/reference/system/xasync/functions/xasyncrun)
    * [XAsyncGetStatus](/reference/system/xasync/functions/xasyncgetstatus)

## See also

[XAsync library overview](/build/core-features/common/async/async-libraries/async-library-xasync)

[Set up async task (example)](/build/core-features/common/async/async-libraries/async-library-xasync-example-setup-async-task)

[Run Microsoft Game Development Kit (GDK) API task (example)](/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task)

[XAsync](/reference/system/xasync/xasync_members)


## Related topics

- [Run Microsoft Game Development Kit API task example](/build/core-features/common/async/async-libraries/async-library-xasync-example-run-gdk-task.md)
- [Set up async task example](/build/core-features/common/async/async-libraries/async-library-xasync-example-setup-async-task.md)
- [XAsync libraries for asynchronous task programming](/build/core-features/common/async/async-libraries/index.md)
- [Generic async task wrapper](/build/core-features/common/async/async-task-function-example.md)
- [Scheduled tasks quickstart](/services/playfab/data-analytics/acting-data/scheduled-tasks/quickstart.md)
