TimeTrigger 类

定义

表示触发后台任务运行的时间事件。

public ref class TimeTrigger sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Background.ITimeTriggerFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
class TimeTrigger final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Background.ITimeTriggerFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class TimeTrigger final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Background.ITimeTriggerFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
public sealed class TimeTrigger
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Background.ITimeTriggerFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class TimeTrigger
function TimeTrigger(freshnessTime, oneShot)
Public NotInheritable Class TimeTrigger
继承
Object Platform::Object IInspectable TimeTrigger
属性
实现

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

以下示例演示如何创建和注册时间触发器。

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

注解

在注册成功之前,必须在清单中声明后台任务。 无需将应用添加到锁屏即可在 Windows 10 中使用后台任务,但仍需要调用 BackgroundExecutionManager.RequestAccessAsync 来请求后台访问。

当设备处于节电模式时,TimeTrigger 不起作用。 如果用户希望应用能够在设备处于节电模式时执行后台活动,他们可以在 “允许应用在后台 设置中运行”面板中对该应用进行例外处理。

注意

此类不是敏捷类,这意味着需要考虑其线程模型和封送处理行为。 有关详细信息,请参阅线程处理和封送处理 (C++/CX) 在多线程环境中使用 Windows 运行时 对象 (.NET)

构造函数

TimeTrigger(UInt32, Boolean)

初始化时间事件触发器的新实例。

属性

FreshnessTime

获取时间事件触发器的间隔。

OneShot

获取时间事件触发器是只使用一次还是每次 使用 FreshnessTime 间隔。

适用于