MaintenanceTrigger MaintenanceTrigger MaintenanceTrigger Class

Definition

Represents a maintenance trigger.

public sealed class MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTriggerpublic sealed class MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTriggerPublic NotInheritable Class MaintenanceTrigger Implements IBackgroundTrigger, IMaintenanceTrigger
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

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

Constructors

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

Initializes a new instance of a maintenance trigger.

public MaintenanceTrigger(UInt32 freshnessTime, Boolean oneShot)public MaintenanceTrigger(UInt32 freshnessTime, Boolean oneShot)Public Sub New(freshnessTime As UInt32, oneShot As Boolean)
Parameters
freshnessTime
System.UInt32 System.UInt32 System.UInt32

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

oneShot
System.Boolean System.Boolean System.Boolean

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

Attributes

Properties

FreshnessTime FreshnessTime FreshnessTime

Gets the interval of a maintenance trigger.

public uint FreshnessTime { get; }public uint FreshnessTime { get; }Public ReadOnly Property FreshnessTime As uint
Value
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.

Attributes

OneShot OneShot OneShot

Gets whether the maintenance trigger is used only once or each time the FreshnessTime interval elapses.

public bool OneShot { get; }public bool OneShot { get; }Public ReadOnly Property OneShot As bool
Value
bool bool bool

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

Attributes