Here I'm sharing some notes on the Background task.
- Background task allows us to run our code, when our app is not in the foreground.
- Starting with Windows 10, you no longer need to place an app on the lock screen in order to register the background tasks.
- Background tasks are limited to 30 seconds of wall-clock usage.
- Respect Cost: Add BackgroundWorkCostValue in run() to get an access on priority from the system.
- Querying cost can prevent the cancellations and incomplete operations.
- Handle System Cancellations:
- Use deferral for any Asynchronous operations.
- App can have more than one background task.
- If it gets the permission, build and register task (add triggers, add system conditions, task.register()).
- Some of the Triggers : DeviceWatcherTrigger , ActivitySensorTrigger , SensorDataThresholdTrigger , ToastNotificationHistoryChangedTrigger , ToastNotificationActionTrigger ,AppointmentStoreNotificationTrigger , ContactStoreNotificationTrigger , EmailStoreNotificationTrigger , BluetoothLEAdvertisementWatcherTrigger , BluetoothLEAdvertisementPublisherTrigger , MediaProcessingTrigger ,SocketActivityTrigger
- User Invoked Constraints: Quite Hours(No toast, No Background task,Active task are cancelled). Still allowed are VOIP toast and Alarm toast.
- Debugging : Visual Studio can trigger. Application logs = Appication & Services Logs ->Microsoft -> BackgroundTaskInfrastructure.