How to disable screensaver and screen inactivity power-down timers

Ron Sipherd 281 Reputation points
2022-03-23T22:18:47.997+00:00

In my several year old slide-show program, to avoid interruptions I have the following VB code:

'Disable screen saver and screen power-down; return True if successful
Try
'Disable display and system timeout timers:
SetThreadExecutionState(EX_STATE.ES_CONTINUOUS Or EX_STATE.ES_SYSTEM_REQUIRED Or EX_STATE.ES_DISPLAY_REQUIRED)
Return True
...

And there is a matching proc to re-enable them.
I'm wondering if there is nowadays a more graceful way, say in the My. namespace, to accomplish this; and to re-enable the timers when I'm done.
But I haven't found one. Any ideas?
Am presently using Visual Studio 2019 on Windows 10.

Developer technologies | VB
0 comments No comments

2 answers

Sort by: Most helpful
  1. Ron Sipherd 281 Reputation points
    2022-03-24T01:21:59.387+00:00

    Thanks! I'll take a look.
    Have used My.Settings before, but not for this.

    Was this answer helpful?


  2. Karen Payne MVP 35,606 Reputation points Volunteer Moderator
    2022-03-23T23:57:02.043+00:00

    There really is nothing more graceful but you could wrap the current code in a custom My module.

    See my Microsoft article VB.NET MySettings deep dive.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.