UWP app in assigned access mode keeps getting sent back to Windows login screen

408 views Asked by At

I'm running a UWP app in assigned access mode, and I'm noticing that, despite changing the power settings so that the screen saver never comes on, quite often the generic Windows 10 login screen will appear, when the app should always be running. The settings are set so the screen and pc will never turn off, on battery or when plugged in. Is there anything I can do to fix this?

1

There are 1 answers

0
Martin Zikmund On

The Windows.System.Display.DisplayRequest class allows you to programmatically request the display to stay on and avoid the screen lock:

var displayRequest = new Windows.System.Display.DisplayRequest();
displayRequest.RequestActive();

When you no longer need the display to stay on, just call RequestRelease():

displayRequest.RequestRelease();

Note the calls are cumulative. This means if you call RequestActive three times, you will then need to call RequestRelease three times as well, otherwise the screen will still stay on. The documentation shows a full sample, which keeps track of the number of times the request has been called and know how many times you need to call RequestRelease (not enough will keep screen on, to many calls will cause an exception). Also note you should keep the instance in memory so that you can call release on it.

Keep in mind keeping the screen from sleeping drains more power, so you should always be mindful to keep the screen on only when necessary from the user's perspective.