BackgroundTaskDeferral Classe

Définition

Représente un report de tâche en arrière-plan retourné par la méthode IBackgroundTaskInstance.GetDeferral .

public ref class BackgroundTaskDeferral sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
class BackgroundTaskDeferral final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class BackgroundTaskDeferral final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
public sealed class BackgroundTaskDeferral
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class BackgroundTaskDeferral
Public NotInheritable Class BackgroundTaskDeferral
Héritage
Object Platform::Object IInspectable BackgroundTaskDeferral
Attributs

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

L’exemple suivant montre comment utiliser un report de tâche en arrière-plan pour retarder la fermeture prématurée d’une tâche pendant que le code asynchrone est toujours en cours d’exécution. Veillez à effectuer tous les reports de tâches en arrière-plan. La plupart des tâches en arrière-plan ont un délai d’expiration après lequel l’application sera suspendue ou arrêtée, qu’il y ait ou non des reports en attente. Toutefois, le fait de laisser des reports de tâches en arrière-plan en suspens nuit à la capacité du système à gérer les durées de vie des processus en temps opportun.

//
// Declare that your background task's Run method makes asynchronous calls by
// using the async keyword.
//
public async void Run(IBackgroundTaskInstance taskInstance)
{
    //
    // Create the deferral by requesting it from the task instance.
    //
    BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

    //
    // Call asynchronous method(s) using the await keyword.
    //
    var result = await ExampleMethodAsync();

    //
    // Once the asynchronous method(s) are done, close the deferral.
    //
    deferral.Complete();
}

Méthodes

Complete()

Informe le système qu’une opération asynchrone associée à une tâche en arrière-plan est terminée.

S’applique à