Search code examples
c#screensaver

Need to disable the screen saver / screen locking in Windows C#/.Net


For a particular application, I need the screen saver to be disabled while it's running. The operator COULD manually turn it off, and then back on later, but the easiest thing to do would be to just keep the screen saver at bay while the application is running.

How do I do this? I've found code for actually turning off the screen saver with SPI_SETSCREENSAVEACTIVE, but I don't think that's what I want.


Solution

  • theoldnewthing has your answer: Use SetThreadExecutionState(ES_DISPLAY_REQUIRED).

    This is used by video players and PowerPoint.