Asked by:
[W8.1]How to execute a background task when I turn my PC on - Windows Store App

Question
-
My app is running on a tablet having Windows 8.1 Pro.
I got lock screen access calling this:
await BackgroundExecutionManager.RequestAccessAsync();
A time trigger run my background task with these conditions (Internet and UserPresent):
// adding condition SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable); SystemCondition userPresentCondition = new SystemCondition(SystemConditionType.UserPresent); builder.AddCondition(internetCondition); builder.AddCondition(userPresentCondition); BackgroundTaskRegistration taskRegistration = builder.Register();
it works properly when my device is turned on but when I turn off my device and restart it again, my background task does not run anymore.
Which condition shall I add (if it is possible)?
s
- Edited by SeDevWP Monday, August 31, 2015 12:29 PM adding info about lock screen
- Edited by Franklin ChenMicrosoft employee, Moderator Tuesday, September 1, 2015 12:40 PM Subject
All replies
-
-
-
-
-
-
I have internet (so internet condition is satisfied) + I have now the session connected condition (I am reconnected). how do I check that my bg is still registered?
s
Hi SeDevWP,
>>how do I check that my bg is still registered?
You can create a new app and check for existing registrations by querying the BackgroundTaskRegistration.AllTasks property and iterating on the result. Check the name of each instance – if it matches the name of the task you’re registering, then break out of the loop and set a flag variable so that you can know if it has been registered:
// // Check for existing registrations of this background task. // foreach (var cur in BackgroundTaskRegistration.AllTasks) { if (cur.Value.Name == name) { // // The task is already registered. // return true; } }
See https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj553413.aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.