Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DeviceUseTrigger class

Applies to Windows and Windows Phone

Represents an event that a Windows Runtime app can trigger to initiate a long-running operation with a device or sensor.

DeviceUseTrigger lets your Windows Runtime app access sensors and peripheral devices in the background, even when your foreground app is suspended. For example, depending on where your app is running, it could use a background task to synchronize data with devices or monitor sensors.

This class can be used in Windows Store apps and Windows Phone Store apps. However, a DeviceUseTrigger background task supports different APIs, and is subject to different policies, depending where it's running (PC or phone). To learn more about these differences, see Accessing sensors and devices from a background task.

For a sample that shows how to use DeviceUseTrigger on a PC, see the Custom USB device sample. For a phone sample, see the Background Sensors sample.

Syntax


var deviceUseTrigger = new Windows.ApplicationModel.Background.DeviceUseTrigger();

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06030000)]

Members

The DeviceUseTrigger class has these types of members:

Constructors

The DeviceUseTrigger class has these constructors.

ConstructorDescription
DeviceUseTrigger Constructor for DeviceUseTrigger. Takes no parameters.

 

Methods

The DeviceUseTrigger class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
RequestAsync(String) Triggers the background task and returns a DeviceTriggerResult indicating success or failure of the trigger request. Takes the DeviceInformation.ID of the device or sensor that the background task will access.
RequestAsync(String,String) Triggers the background task and returns a DeviceTriggerResult indicating success or failure of the trigger request. Takes the DeviceInformation.ID of the device or sensor that the background task will access, and an optional app-specific string passed to the background task identifying which operation to perform.

 

Remarks

The DeviceInformation.Id passed to the RequestAsync method must match the device or sensor that will perform the background operation. The DeviceInformation.Id is used by Windows to ensure that policy requirements are met. For more about policy requirements, see Accessing sensors and devices from a background task.

  • Applies to Windows Phone

Note  Before your app triggers a background task on a phone, it must first call RequestAccessAsync to check if the app is able to request a background task. This check is not required when your app is running on a PC.

Requirements

Minimum supported client

Windows 8.1 [Windows Store apps only]

Minimum supported server

Windows Server 2012 R2 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.ApplicationModel.Background
Windows::ApplicationModel::Background [C++]

Metadata

Windows.winmd

See also

Object
IBackgroundTrigger

 

 

Show:
© 2014 Microsoft