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

Time イベント トリガーを 1 回だけ使用するか、 FreshnessTime 間隔が経過するたびに使用するかを取得します。

適用対象