共用方式為


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來要求背景存取。

當裝置處於省電模式時,TimeTriggers 無法運作。 如果使用者希望應用程式能夠在裝置處於省電模式時執行背景活動,他們可以在 [讓應用程式在背景 設定] 面板中執行該應用程式的例外狀況。

注意

這個類別不是敏捷式的,這表示您需要考慮其執行緒模型和封送處理行為。 如需詳細資訊,請參閱執行緒和封送處理 (C++/CX) 在多執行緒環境中使用 Windows 執行階段 物件 (.NET)

建構函式

TimeTrigger(UInt32, Boolean)

初始化時間事件觸發程式的新實例。

屬性

FreshnessTime

取得時間事件觸發程式的間隔。

OneShot

取得時間事件觸發程式只會使用一次,或每次 FreshnessTime 間隔經過時。

適用於