locked
How to fire background task trigger on Unlock of screen

    Question

  •  I am writing an 8.1 PC app.  The background task is in a WinRT component included in the solution.

    I want to fire background task event when the user unlocks the screen.  I have tried the "UserPresent" and the "SessionConnected" system Trigger types but they are not working.  I have already searched the msdn website and read the page with all the trigger types.  I have also added this line of code before to ensure that the app is on the lockscreen.

    BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();

    I assumed that the definition for the "UserPresent" trigger meant that the task would run everytime the screen was unlocked.  Is this not what is supposed to happen?  If so, is there another trigger that does run when the screen is unlocked?

    Tuesday, July 29, 2014 12:07 AM

Answers

  • Hi,

    UserAway and UserPresent can fire background task trigger when computer in lockscreen or off lockscreen. If you want to know when user off lockscreen you can use UserPresent. But if you want to trigger the background when UserPresent, you must add the app in the lock screen. I create an app which can trigger background task when the screen is unlocked.You can add breakpoint in the OnCompleted event when you debug the app, if the event can fire, that indicate the background task can run successfully. When you screen is from lockscreen to unlocked screen, you would find the background task can run successfully.

    I upload the project into oneDrive that you can refer to:

    http://1drv.ms/1zy9P99

    http://1drv.ms/1zy9Rhf

    Best Wishes!


    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. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, July 31, 2014 7:03 AM

All replies

  • Hi,

    There is the note for "UserPresent"
    An app must be placed on the lock screen before it can successfully register background tasks using this trigger type.

    From http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.applicationmodel.background.systemtriggertype.aspx

    Here is the document for lock screen.
    http://msdn.microsoft.com/en-us/library/windows/apps/hh779720.aspx

    Best Wishes!


    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. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Tuesday, July 29, 2014 1:41 AM
  • Thank you.  I read both pages and checked my app again.   I gave my app the lock screen capability and added it to the lock screen after launching.  The background task still is not running for the "UserPresent" trigger when I unlock my screen.  

    Are there any other triggers to accomplish this or am I assuming the trigger should work when it is not supposed to?

    Tuesday, July 29, 2014 2:03 AM
  • Hi,

    UserAway and UserPresent can fire background task trigger when computer in lockscreen or off lockscreen. If you want to know when user off lockscreen you can use UserPresent. But if you want to trigger the background when UserPresent, you must add the app in the lock screen. I create an app which can trigger background task when the screen is unlocked.You can add breakpoint in the OnCompleted event when you debug the app, if the event can fire, that indicate the background task can run successfully. When you screen is from lockscreen to unlocked screen, you would find the background task can run successfully.

    I upload the project into oneDrive that you can refer to:

    http://1drv.ms/1zy9P99

    http://1drv.ms/1zy9Rhf

    Best Wishes!


    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. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, July 31, 2014 7:03 AM
  • Go to view -> toolsbar -> debug location and see if you cn start the background task your self. maybe its wrongly registered

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, August 01, 2014 8:25 AM