TimeTrigger Classe

Définition

Représente un événement de temps qui déclenche l’exécution d’une tâche en arrière-plan.

public ref class TimeTrigger sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Background.ITimeTriggerFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [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 TimeTrigger final
/// [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)]
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Background.ITimeTriggerFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class TimeTrigger final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Background.ITimeTriggerFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[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 TimeTrigger
[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)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Background.ITimeTriggerFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class TimeTrigger
function TimeTrigger(freshnessTime, oneShot)
Public NotInheritable Class TimeTrigger
Héritage
Object Platform::Object IInspectable TimeTrigger
Attributs
Implémente

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 créer et inscrire un déclencheur de temps.

//
// A friendly task name.
//
String name = "ExampleTaskName";

//
// Must be the same entry point that is specified in the manifest.
//
String taskEntryPoint = "ExampleNamespace.ExampleTaskName";

//
// A time trigger that repeats at 15-minute intervals.
//
IBackgroundTrigger trigger = new TimeTrigger(15, false);

//
// Builds the background task.
//
BackgroundTaskBuilder builder = new BackgroundTaskBuilder();

builder.Name = name;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);

//
// Registers the background task, and get back a BackgroundTaskRegistration object representing the registered task.
//
BackgroundTaskRegistration task = builder.Register();

Remarques

La tâche en arrière-plan doit être déclarée dans le manifeste pour que l’inscription puisse réussir. Vous n’avez pas besoin d’ajouter l’application à l’écran de verrouillage pour utiliser des tâches en arrière-plan dans Windows 10, mais vous devez toujours appeler BackgroundExecutionManager.RequestAccessAsync pour demander l’accès en arrière-plan.

TimeTriggers ne fonctionne pas lorsque l’appareil est en mode économiseur de batterie. Si l’utilisateur souhaite que l’application puisse effectuer une activité en arrière-plan lorsque l’appareil est en mode économiseur de batterie, il peut faire une exception pour cette application dans le panneau Laisser les applications s’exécuter dans le panneau des paramètres d’arrière-plan .

Notes

Cette classe n’est pas agile, ce qui signifie que vous devez prendre en compte son modèle de thread et son comportement de marshaling. Pour plus d’informations, consultez Threading and Marshaling (C++/CX) et Using Windows Runtime objects in a multithreaded environment (.NET).

Constructeurs

TimeTrigger(UInt32, Boolean)

Initialise une nouvelle instance d’un déclencheur d’événement de temps.

Propriétés

FreshnessTime

Obtient l’intervalle d’un déclencheur d’événement de temps.

OneShot

Obtient si le déclencheur d’événement de temps ne sera utilisé qu’une seule fois ou chaque fois que l’intervalle FreshnessTime s’écoule .

S’applique à