Skip to content

Instantly share code, notes, and snippets.

View JonasNilson's full-sized avatar
🐛
Smashing bugs

Jonas Nilson JonasNilson

🐛
Smashing bugs
  • Sweden
  • 06:39 (UTC +01:00)
View GitHub Profile
@brianhassel
brianhassel / PreventSleep.cs
Last active June 24, 2024 18:42
Prevent Computer Sleep in C#
internal static class NativeMethods {
public static void PreventSleep() {
SetThreadExecutionState(ExecutionState.EsContinuous | ExecutionState.EsSystemRequired);
}
public static void AllowSleep() {
SetThreadExecutionState(ExecutionState.EsContinuous);
}