Represents a time event that triggers a background task to run.
public : sealed class TimeTrigger : IBackgroundTrigger, ITimeTrigger
struct winrt::Windows::ApplicationModel::Background::TimeTrigger : IBackgroundTrigger, ITimeTrigger
public sealed class TimeTrigger : IBackgroundTrigger, ITimeTrigger
Public NotInheritable Class TimeTrigger Implements IBackgroundTrigger, ITimeTrigger
var timeTrigger = new timeTrigger(freshnessTime, oneShot);
Windows 10 (introduced v10.0.10240.0)
Windows.Foundation.UniversalApiContract (introduced v1)
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();
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.
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).
|TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean) TimeTrigger(UInt32, Boolean)||
Initializes a new instance of a time event trigger.
|FreshnessTime FreshnessTime FreshnessTime FreshnessTime FreshnessTime||
Gets the interval of a time event trigger.
|OneShot OneShot OneShot OneShot OneShot||
Gets whether the time event trigger will be used only once or each time the FreshnessTime interval elapses.