MaintenanceTrigger MaintenanceTrigger MaintenanceTrigger MaintenanceTrigger MaintenanceTrigger Class

Definition

Represents a maintenance trigger.

public : sealed class MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTrigger
struct winrt::Windows::ApplicationModel::Background::MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTrigger
public sealed class MaintenanceTrigger : IBackgroundTrigger, IMaintenanceTrigger
Public NotInheritable Class MaintenanceTrigger Implements IBackgroundTrigger, IMaintenanceTrigger
var maintenanceTrigger = new maintenanceTrigger(freshnessTime, oneShot);
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) MaintenanceTrigger(UInt32, Boolean)

Initializes a new instance of a maintenance trigger.

Properties

FreshnessTime FreshnessTime FreshnessTime FreshnessTime FreshnessTime

Gets the interval of a maintenance trigger.

OneShot OneShot OneShot OneShot OneShot

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