Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.71 KB

maintenancetrigger.md

File metadata and controls

56 lines (43 loc) · 1.71 KB
-api-id -api-type
T:Windows.ApplicationModel.Background.MaintenanceTrigger
winrt class

Windows.ApplicationModel.Background.MaintenanceTrigger

-description

Represents a maintenance trigger.

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

-see-also