MaintenanceTrigger MaintenanceTrigger MaintenanceTrigger MaintenanceTrigger Class

Represents a maintenance trigger.

Syntax

Declaration

public sealed class MaintenanceTriggerpublic sealed class MaintenanceTriggerPublic NotInheritable Class MaintenanceTrigger

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 summary

Initializes a new instance of a maintenance trigger.

Properties summary

Gets the interval of a maintenance trigger.

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

Constructors

  • MaintenanceTrigger(System.UInt32,System.Boolean)
    MaintenanceTrigger(System.UInt32,System.Boolean)
    MaintenanceTrigger(System.UInt32,System.Boolean)
    MaintenanceTrigger(System.UInt32,System.Boolean)

    Initializes a new instance of a maintenance trigger.

    public MaintenanceTrigger(System.UInt32,System.Boolean)public MaintenanceTrigger(System.UInt32,System.Boolean)Public Function MaintenanceTrigger(System.UInt32,System.Boolean) As

    Parameters

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

    Property Value

    • uint
      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 bool OneShot { get; }public bool OneShot { get; }Public ReadOnly Property OneShot As bool

    Property Value

    • bool
      bool
      bool
      bool

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.ApplicationModel.Background.dll