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

# Procédure : utilisation de rappels différés

> Procédure : utilisation de rappels différés

## Exemple

Utilisez une file d'attente de tâches pour soumettre des rappels dans le futur à l'aide de l'API `XTaskQueueSubmitDelayedCallback`. Vous pouvez ainsi réessayer un appel ayant échoué après un court délai, ou l'utiliser comme minuteur peu coûteux pour des événements périodiques.

L'exemple suivant appelle 10 rappels, une fois toutes les 500 ms.

```c++ theme={null}
void SubmittingDelayedCallback()  
{  
    XTaskQueueHandle queue;  
  
    HRESULT hr = XTaskQueueCreate(  
        XTaskQueueDispatchMode::ThreadPool,  
        XTaskQueueDispatchMode::ThreadPool,  
        &queue);  
  
    if (FAILED(hr))  
    {  
        printf("Failed to create task queue: 0x%x\r\n", hr);  
        return;  
    }  
  
    struct CallContext  
    {  
        DWORD count;  
        XTaskQueueHandle queue;  
        XTaskQueueCallback* callback;  
    } callContext;  
  
    auto callback = [](void* context, bool cancel)  
    {  
        CallContext *callContext = static_cast<CallContext*>(context);  
        callContext->count++;  
        printf("Periodic callback %d\r\n", callContext->count);  
        if (callContext->count != 10 && !cancel)  
        {  
            HRESULT hr = XTaskQueueSubmitDelayedCallback(  
                callContext->queue,  
                XTaskQueuePort::Completion,  
                500,  
                callContext,  
                callContext->callback);  
  
            if (FAILED(hr))  
            {  
                printf("Failed submitting next callback: 0x%x\r\n", hr);  
                callContext->count = 10; // Prevents us from waiting forever.  
            }  
        }  
    };  
  
    callContext.count = 0;  
    callContext.queue = queue;  
    callContext.callback = callback;  
  
    // Use the task queue to make 10 periodic calls.  
    hr = XTaskQueueSubmitDelayedCallback(  
        queue,  
        XTaskQueuePort::Completion,  
        500,  
        &callContext,  
        callback);  
  
    if (FAILED(hr))  
    {  
        printf("Failed submitting delayed callback: 0x%x\r\n", hr);  
        XTaskQueueCloseHandle(queue);  
        return;  
    }  
  
    // Now, wait for all of the calls to be completed.  
    while (callContext.count != 10)  
    {  
        Sleep(1000);  
    }  
  
    XTaskQueueTerminate(queue, true, nullptr, nullptr);  
    XTaskQueueCloseHandle(queue);  
}  
```

## Exemple de sortie

```
Periodic callback 1  
Periodic callback 2  
Periodic callback 3  
Periodic callback 4  
Periodic callback 5  
Periodic callback 6  
Periodic callback 7  
Periodic callback 8  
Periodic callback 9  
Periodic callback 10  
```

## Voir aussi

[Conception de la file d'attente de tâches](/fr/build/core-features/common/async/async-task-queue-design)


## Related topics

- [XBOX Rapid Updates](/fr/publishing/game-publishing/concepts/certification/xbox-rapid-updates.md)
- [Notes de version de PlayFab Party](/fr-CA/services/playfab/multiplayer/networking/release-notes.md)
- [XR048 Utilisation des paramètres de profil](/fr-CA/publishing/certification/fma/xr-048.md)
- [XR-048 Utilisation des paramètres de profil](/fr-CA/publishing/certification/xr/xr-048.md)
- [Informations supplémentaires](/fr/publishing/game-publishing/concepts/certification/certification-supplemental-info.md)
