Standby.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Runtime.InteropServices;
  2. namespace MediaBrowser.ServerApplication.Native
  3. {
  4. /// <summary>
  5. /// Class NativeApp
  6. /// </summary>
  7. public static class Standby
  8. {
  9. public static void PreventSystemStandby()
  10. {
  11. SystemHelper.ResetStandbyTimer();
  12. }
  13. internal enum EXECUTION_STATE : uint
  14. {
  15. ES_NONE = 0,
  16. ES_SYSTEM_REQUIRED = 0x00000001,
  17. ES_DISPLAY_REQUIRED = 0x00000002,
  18. ES_USER_PRESENT = 0x00000004,
  19. ES_AWAYMODE_REQUIRED = 0x00000040,
  20. ES_CONTINUOUS = 0x80000000
  21. }
  22. public class SystemHelper
  23. {
  24. [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  25. static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
  26. public static void ResetStandbyTimer()
  27. {
  28. EXECUTION_STATE es = SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
  29. }
  30. }
  31. }
  32. }