Svish
Svish

Reputation: 157971

C#: How to prevent a laptop from going into Stand-By

How can I do this in a C# program? I'm pretty sure it should be possible, since various media programs for example do this so the computer doesn't go into stand-by while watching a movie, etc.

So, if I for example create a plain and basic WinForm application, what do I need to do to prevent a laptop from going into Stand-By as long as this application is running?

Upvotes: 9

Views: 7769

Answers (1)

Andrew Arnott
Andrew Arnott

Reputation: 81771

I think you'll have to P/Invoke. But don't be scared... it's pretty easy.

SetThreadExecutionState is your friend. It's available in the PInvoke project, also available on NuGet.

Upvotes: 12

Related Questions