BackgroundTaskDeferral Klasse

Definition

Stellt eine Hintergrundaufgabesverzögerung dar, die von der IBackgroundTaskInstance.GetDeferral-Methode zurückgegeben wird.

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
Vererbung
Object Platform::Object IInspectable BackgroundTaskDeferral
Attribute

Windows-Anforderungen

Gerätefamilie
Windows 10 (eingeführt in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v1.0)

Beispiele

Im folgenden Beispiel wird gezeigt, wie Sie mithilfe einer Hintergrundaufgabenverzögerung das vorzeitige Schließen einer Aufgabe verzögern, während asynchroner Code noch ausgeführt wird. Stellen Sie sicher, dass Sie alle Zurückstellungen von Hintergrundaufgaben durchführen. Die meisten Hintergrundaufgaben weisen ein Timeout auf, nach dem die App angehalten oder beendet wird, unabhängig davon, ob Verzögerungen ausstehen. Wenn jedoch ausstehende Hintergrundaufgaben zurückbleiben, wird die Fähigkeit des Systems beeinträchtigt, Prozesslebensdauern rechtzeitig zu verwalten.

//
// 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();
}

Methoden

Complete()

Informiert das System darüber, dass ein asynchroner Vorgang, der einer Hintergrundaufgabe zugeordnet ist, abgeschlossen wurde.

Gilt für: