TimeTrigger TimeTrigger TimeTrigger TimeTrigger Class

Represents a time event that triggers a background task to run.

Syntax

Declaration

public sealed class TimeTriggerpublic sealed class TimeTriggerPublic NotInheritable Class TimeTriggerpublic sealed class TimeTrigger

Remarks

The background task must be declared in the manifest before the registration can be successful. You do not need to add the app to the lock screen in order to use background tasks in Windows 10, but you still need to call RequestAccessAsync(String) to request background access.

TimeTriggers, and other background triggers, do not work when the device is in battery saver mode. If the user wants the app to be able to perform background activity when the device is in battery saver mode, they can make an exception for that app in the Let apps run in the background settings panel.

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 time 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 time trigger that repeats at 15-minute intervals.
//
IBackgroundTrigger trigger = new TimeTrigger(15, false);

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

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

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

Constructors summary

Initializes a new instance of a time event trigger.

Properties summary

Gets the interval of a time event trigger.

Gets whether the time event trigger will be used only once or each time the FreshnessTime interval elapses.

Constructors

  • TimeTrigger(UInt32, Boolean)
    TimeTrigger(UInt32, Boolean)
    TimeTrigger(UInt32, Boolean)
    TimeTrigger(UInt32, Boolean)

    Initializes a new instance of a time event trigger.

    public TimeTrigger(UInt32 freshnessTime, Boolean oneShot)public New(UInt32 freshnessTime, Boolean oneShot)Public Sub New(freshnessTime As UInt32, oneShot As Boolean)public TimeTrigger(UInt32 freshnessTime, Boolean oneShot)

    Parameters

    • freshnessTime
      System.UInt32
      System.UInt32
      System.UInt32
      System.UInt32

      Specifies the number of minutes to wait before scheduling the background task. The system schedules the task within 15 minutes after freshnessTime elapses. If the OneShot property is false, freshnessTime specifies the interval between recurring tasks.

      Note

      If FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task.

    • oneShot
      System.Boolean
      System.Boolean
      System.Boolean
      System.Boolean

      True if the time event trigger will be used once; false if it will be used each time freshnessTime elapses.

Properties

  • FreshnessTime
    FreshnessTime
    FreshnessTime
    FreshnessTime

    Gets the interval of a time event trigger.

    public uint FreshnessTime { get; }public uint FreshnessTime { get; }Public ReadOnly Property FreshnessTime As uintpublic uint FreshnessTime { get; }

    Property Value

    • uint
      uint
      uint
      uint

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

    Remarks

    The system uses a 15-minute tick frequency for timer requests. A time-triggered background task is scheduled on the next tick after FreshnessTime elapses. If the OneShot property is false, FreshnessTime specifies the interval for a recurring task.

    Note

    If FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task.

  • OneShot
    OneShot
    OneShot
    OneShot

    Gets whether the time event trigger will be used only once or each time the FreshnessTime interval elapses.

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

    Property Value

    • bool
      bool
      bool
      bool

      True if the time event trigger will be used once; false if it will be 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.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.ApplicationModel.Background.dll