Maintenance​Trigger Maintenance​Trigger Maintenance​Trigger Maintenance​Trigger Class

Definition

Represents a maintenance trigger.

public : sealed class MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTriggerpublic sealed class MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTriggerPublic NotInheritable Class MaintenanceTrigger Implements IBackgroundTrigger, IMaintenanceTrigger// 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 maintenance 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 system trigger that goes off every 15 minutes as long as the device is plugged in to AC power.
//
MaintenanceTrigger trigger = new MaintenanceTrigger(15, false);

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

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

//
// Register the background task, and get back a BackgroundTaskRegistration object representing the registered task.
//
BackgroundTaskRegistration task = builder.Register();
//
// A friendly task name.
//
var name = "ExampleTaskName";

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

//
// A system trigger that goes off every 15 minutes as long as the device is plugged in to AC power.
//
var trigger = new Windows.ApplicationModel.Background.MaintenanceTrigger(15, false);

//
// Build the background task.
//
var builder = new Windows.ApplicationModel.Background.BackgroundTaskBuilder();

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

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

Remarks

Background tasks that use a maintenance trigger run only when the system is connected to AC power.

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

MaintenanceTrigger(UInt32, Boolean) MaintenanceTrigger(UInt32, Boolean) MaintenanceTrigger(UInt32, Boolean) MaintenanceTrigger(UInt32, Boolean)

Initializes a new instance of a maintenance trigger.

public : MaintenanceTrigger(unsigned int freshnessTime, bool oneShot)public MaintenanceTrigger(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

The number of minutes to wait before scheduling the background task. The system schedules the task within 15 minutes after freshnessTime elapses.

oneShot
bool Boolean Boolean Boolean

True if the maintenance trigger is used once; false if it is used each time the freshnessTime interval elapses.

Properties

FreshnessTime FreshnessTime FreshnessTime FreshnessTime

Gets the interval of a maintenance trigger.

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

The number of minutes to wait before scheduling the background task. The system schedules the task within 15 minutes after FreshnessTime elapses.

OneShot OneShot OneShot OneShot

Gets whether the maintenance trigger is 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 maintenance trigger is used once; false if it is used each time the FreshnessTime interval elapses.