Compartilhar via


Run Microsoft Game Development Kit API task example

This topic provides an example of how to run a Microsoft Game Development Kit (GDK) API task. Async Microsoft Game Development Kit (GDK) API functions internally implement the work callback. However, it still runs as directed by the task queue as specified in the async block. Running these methods requires the async block and whatever parameters are needed for the API.

// Set up the async block and completion callback.
XAsyncBlock* async = new XAsyncBlock{};
async->queue = taskQueue;
async->context = nullptr;
async->callback = [](XAsyncBlock* async)
{
    XUserHandle newUser = nullptr;
    HRESULT result = XUserAddResult(async, &newUser);
    // Handle the completion callback.
    delete async;
};

// Start the async call.
HRESULT hr = XUserAddAsync(XUserAddOptions::None, async);
if (FAILED(hr))
{
    delete async;
}

This code doesn't differ much from the code to run generic tasks. Instead of using XAsyncRun with a work callback, you call into the API that you want to use. The async block is set up in the same way. The difference there is that XUserAddAsync has data to be retrieved from the call that's done in the completion callback with XUserAddResult.

See also

XAsync library overview

Set up async task (example)

Run simple task (example)

XAsync