UWP app temporary stops when screen is off

142 views Asked by At

I have made a very simple Windows 10 UWP app. The only thing it does is printing date and time to a textblock every second. It look like this:

12-05-2021 19:42:50
12-05-2021 19:42:51
12-05-2021 19:42:52
12-05-2021 19:42:53

This work fine when the screen is on, but when the screen turns off it stops until the screen is turned on again. It then could look like this with screen off for a minute:

12-05-2021 19:42:50
12-05-2021 19:42:51 (Screen goes off)
12-05-2021 19:43:51 (Screen goes on - Textblock not updated while screen was off)
12-05-2021 19:43:52 (But continues printing after screen turns on)

Note: When debugging with Visual studio everything works fine even when screen has been off. So only when I start program from startmenu the problem occurs. I guess Visual Studio keep program running.

Is there a way to get UWP to continue working while screen is off?

UPDATE: The simple program I made was just to test if there where something wrong with my homeautomation program. My homeautomation program is a server/client program which connects to 2 raspberry pies. 1 pie controls lights and monitoring light levels and motionsensor. The other controls my garagedoor, monitoring doors, temp, humi and my mailbox. So when the screen shuts down I don't get status from the RPis before i actually wake up the screen. Maybe I should not have made this server as UWP? How would you guys have made a program to control and monitoring devices over the network? Im not sure how to implement "extended execution" in my program.

1

There are 1 answers

0
Ivan Ičin On

There is no way that is meant to work in 100% of cases. But assuming that your device has enough resources while doing this operation so that it doesn't need to suspend it to prioritize something else this should help you: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution