TimeTrigger TimeTrigger TimeTrigger TimeTrigger Class

Definition

Represents a time event that triggers a background task to run.

public : sealed class TimeTrigger : IBackgroundTrigger, ITimeTriggerpublic sealed class TimeTrigger : IBackgroundTrigger, ITimeTriggerPublic NotInheritable Class TimeTrigger Implements IBackgroundTrigger, ITimeTrigger// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following example shows how to create and register a time trigger.

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

Remarks

The background task must be declared in the manifest before the registration can be successful. You do not need to add the app to the lock screen in order to use background tasks in Windows 10, but you still need to call RequestAccessAsync to request background access.

TimeTriggers, and other background triggers, do not work when the device is in battery saver mode. If the user wants the app to be able to perform background activity when the device is in battery saver mode, they can make an exception for that app in the Let apps run in the background settings panel.

Note

: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

Constructors

TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean)

Initializes a new instance of a time event trigger.

public : TimeTrigger(unsigned int freshnessTime, bool oneShot)public TimeTrigger(UInt32 freshnessTime, Boolean oneShot)Public Sub New(freshnessTime As UInt32, oneShot As Boolean)// You can use this method in JavaScript.
Parameters
freshnessTime
unsigned int UInt32 UInt32 UInt32

Specifies the number of minutes to wait before scheduling the background task. The system schedules the task within 15 minutes after freshnessTime elapses. If the OneShot property is false, freshnessTime specifies the interval between recurring tasks.

Note

If FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task.

oneShot
bool Boolean Boolean Boolean

True if the time event trigger will be used once; false if it will be used each time freshnessTime elapses.

Properties

FreshnessTime FreshnessTime FreshnessTime FreshnessTime

Gets the interval of a time event trigger.

public : unsigned int FreshnessTime { get; }public uint FreshnessTime { get; }Public ReadOnly Property FreshnessTime As uint// You can use this property in JavaScript.
Value
unsigned int uint uint uint

Specifies the number of minutes to wait before scheduling the background task. The minimum value for FreshnessTime is 15 minutes. The system schedules the task within 15 minutes after FreshnessTime elapses.

Remarks

The system uses a 15-minute tick frequency for timer requests. A time-triggered background task is scheduled on the next tick after FreshnessTime elapses. If the OneShot property is false, FreshnessTime specifies the interval for a recurring task.

Note

To understand the timeframe within which the time trigger may fire, consider a FreshnessTime set to 15 minutes. Because the system schedules the task within 15 minutes after FreshnessTime elapses, it may be up to 30 minutes before the time trigger fires.

OneShot OneShot OneShot OneShot

Gets whether the time event trigger will be used only once or each time the FreshnessTime interval elapses.

public : PlatForm::Boolean OneShot { get; }public bool OneShot { get; }Public ReadOnly Property OneShot As bool// You can use this property in JavaScript.
Value
PlatForm::Boolean bool bool bool

True if the time event trigger will be used once; false if it will be used each time the FreshnessTime interval elapses.