The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[W8.1]How to execute a background task when I turn my PC on - Windows Store App RRS feed

  • 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

    Monday, August 31, 2015 12:10 PM

All replies

  • it should start again, but what is the interval that the timetrigger set?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, August 31, 2015 12:12 PM
  • it is 15'

    doing it:

                builder.SetTrigger(new TimeTrigger(15, false)); // 
    


    s


    • Edited by SeDevWP Monday, August 31, 2015 12:47 PM
    Monday, August 31, 2015 12:44 PM
  • It should work, are you sure your device can meet all conditions after rebooting?

    Have you check if your background task has been registered after rebooting?


    Best Regards,
    Please remember to mark the replies as answers if they help

    Tuesday, September 1, 2015 12:47 PM
  • how do I check it?

    s

    Tuesday, September 1, 2015 12:49 PM
  • 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

    Tuesday, September 1, 2015 12:57 PM
  • 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.

    Wednesday, September 9, 2015 3:09 AM
    Moderator