-api-id | -api-type |
---|---|
T:Windows.ApplicationModel.Background.DeviceUseTrigger |
winrt class |
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 UWP app and Windows Phone 8.x app. 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.
Important
This trigger cannot be used with single-process background tasks.
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.
For more about policy requirements, see Accessing sensors and devices from a background task
Before your app triggers a background task on a phone, it must first call BackgroundExecutionManager.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.