summaryrefslogtreecommitdiffstats
path: root/win/C#/HandBrake.ApplicationServices/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices/Functions')
-rw-r--r--win/C#/HandBrake.ApplicationServices/Functions/Win32.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Win32.cs b/win/C#/HandBrake.ApplicationServices/Functions/Win32.cs
index a3caf38ab..72e4d8db0 100644
--- a/win/C#/HandBrake.ApplicationServices/Functions/Win32.cs
+++ b/win/C#/HandBrake.ApplicationServices/Functions/Win32.cs
@@ -139,5 +139,32 @@ namespace HandBrake.ApplicationServices.Functions
/// </summary>
CTRL_CLOSE = 2,
}
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
+
+ [FlagsAttribute]
+ public enum EXECUTION_STATE : uint
+ {
+ ES_SYSTEM_REQUIRED = 0x00000001,
+ ES_CONTINUOUS = 0x80000000,
+ ES_AWAYMODE_REQUIRED = 0x00000040
+ }
+
+ /// <summary>
+ /// Prevent the system from sleeping
+ /// </summary>
+ public void PreventSleep()
+ {
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
+ }
+
+ /// <summary>
+ /// Allow the system to sleep.
+ /// </summary>
+ public void AllowSleep()
+ {
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
+ }
}
}