Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 1.97 KB

systemcondition.md

File metadata and controls

63 lines (47 loc) · 1.97 KB
-api-id -api-type
T:Windows.ApplicationModel.Background.SystemCondition
winrt class

Windows.ApplicationModel.Background.SystemCondition

-description

Represents a system condition that must be in effect for a background task to run.

-remarks

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 expands on the example shown in SystemTrigger by also adding a condition to the background task.

//
// 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 whenever the time zone is changed, or a change occurs with daylight savings time.
//
IBackgroundTrigger trigger = new SystemTrigger(SystemTriggerType.TimeZoneChange, false);

//
// A system condition indicating that the background task shouldn't run until the user is present.
//
SystemCondition condition = new SystemCondition(SystemConditionType.UserPresent)

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

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

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

-see-also