Dela via


TimeTrigger Class

Definition

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

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
Inheritance
Object Platform::Object IInspectable TimeTrigger
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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 BackgroundExecutionManager.RequestAccessAsync to request background access.

TimeTriggers 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)

Initializes a new instance of a time event trigger.

Properties

FreshnessTime

Gets the interval of a time event trigger.

OneShot

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

Applies to