Search code examples
uwpbackground-task

UWP background task for logging in/ logging out


I am trying to find a background task which will get triggered when the user signs out and signs back in. I looked into some of the SystemTrigger types and came across SessionsConnected trigger. My understanding is that this is a system trigger when a session ends and that means this would be triggered on a log out and log back in. Is there a different way to use this trigger for sign in and sign out? Or is there a different trigger to achieve this.


Solution

  • Currently, there are no other UWP APIs that could directly detect the user logging in/logging out. I think the SessionsConnected trigger that you found does the work in some scenarios.

    But if you want to have a separate event for both logging in and logging out actions, then you might need to use the SystemEvents.SessionEnded Event and SystemEvents.SessionSwitch Event. These are .Net APIs that need to be used in desktop apps. So you have to create a desktop app and package the desktop app together with the UWP app using desktop bridge.