locked
What is the "Session" in SystemTriggerType?

    Question

  •       In API Windows.ApplicationModel.Background,  there are three SystemTriggerType as SessionStart, SessionConnected and SessionDisconnected. But, I don't understand and how to use?
    Tuesday, November 1, 2011 3:08 AM

Answers

  • Hi Jones,

    The term session refers to a Windows user session. These events are available only to lockscreen apps. An app can figure out its lockscreen state using the lockscreen events.

    -Jeff


    Jeff Sanders (MSFT)
    Wednesday, November 2, 2011 1:09 PM
    Moderator
  • Hi Jones,

    I took the BackgroundTaskSample and modified it to capture the Windows.ApplicationModel.Background.SystemTriggerType.sessionStart event

    First in program.js, I modified the function registerSampleJavaScriptBackgroundTask and had it set the SystemTrigger to Windows.ApplicationModel.Background.SystemTriggerType.sessionStart.

    Then I modified the UI to dump some localSettings so I could see if the background task was being invoked.  I added this to initialize:          var localSettings = Windows.Storage.ApplicationData.current.localSettings;
            sdkSample.displayError(localSettings.values["loginfo"]);

     

    Then I added this to backgroundtask.js to set a value so that I could tell if the systemTrigger was being called:

        var localSettings = Windows.Storage.ApplicationData.current.localSettings;
        localSettings.values["loginfo"] = "Background " + backgroundTask.taskInstance.task.name + " Starting...";

    Finally I add the icons to the manifest  for Wide Logo, Badge Logo, Gave a short name and ensured Show Name was enabled, said that it was Toast Capable and Lock Screen Notifications I set to Badge and Title Text.

    Then I started the app in the debugger and registered the JavaScript Sample background task.  (note the UI should show a blue 'undefined' text.  Then I quit the app and added it as the lockscreen app.  I logged off, logged back on and waited so that the background task to execute.  Then I start the app again and the 'Background' text appeared in the UI indicating that the startingEvent did indeed kick off when I logged on.

    -Jeff


    Jeff Sanders (MSFT)
    • Marked as answer by Bob_Bao Wednesday, December 7, 2011 9:24 AM
    Thursday, November 3, 2011 8:29 PM
    Moderator

All replies

  • Hi Jones,

    The term session refers to a Windows user session. These events are available only to lockscreen apps. An app can figure out its lockscreen state using the lockscreen events.

    -Jeff


    Jeff Sanders (MSFT)
    Wednesday, November 2, 2011 1:09 PM
    Moderator
  •           Thanks for your prompt reply. but still fail to trigger background task after add my app into lockscreen, is there any sample code for reference?

    Thursday, November 3, 2011 1:49 AM
  • Hi Jones,

    I took the BackgroundTaskSample and modified it to capture the Windows.ApplicationModel.Background.SystemTriggerType.sessionStart event

    First in program.js, I modified the function registerSampleJavaScriptBackgroundTask and had it set the SystemTrigger to Windows.ApplicationModel.Background.SystemTriggerType.sessionStart.

    Then I modified the UI to dump some localSettings so I could see if the background task was being invoked.  I added this to initialize:          var localSettings = Windows.Storage.ApplicationData.current.localSettings;
            sdkSample.displayError(localSettings.values["loginfo"]);

     

    Then I added this to backgroundtask.js to set a value so that I could tell if the systemTrigger was being called:

        var localSettings = Windows.Storage.ApplicationData.current.localSettings;
        localSettings.values["loginfo"] = "Background " + backgroundTask.taskInstance.task.name + " Starting...";

    Finally I add the icons to the manifest  for Wide Logo, Badge Logo, Gave a short name and ensured Show Name was enabled, said that it was Toast Capable and Lock Screen Notifications I set to Badge and Title Text.

    Then I started the app in the debugger and registered the JavaScript Sample background task.  (note the UI should show a blue 'undefined' text.  Then I quit the app and added it as the lockscreen app.  I logged off, logged back on and waited so that the background task to execute.  Then I start the app again and the 'Background' text appeared in the UI indicating that the startingEvent did indeed kick off when I logged on.

    -Jeff


    Jeff Sanders (MSFT)
    • Marked as answer by Bob_Bao Wednesday, December 7, 2011 9:24 AM
    Thursday, November 3, 2011 8:29 PM
    Moderator
  •      Work it!! Thanks very much for your help!
    Friday, November 4, 2011 6:42 AM