终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 line
821 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.MorkT
  8. {
  9. public class PreventSleep
  10. {
  11. [DllImport("kernel32.dll")]
  12. static extern uint SetThreadExecutionState(uint dwThreadId);
  13. const uint ES_SYSTEM_REQUIRED = 0x00000001;
  14. const uint ES_DISPLAY_REQUIRED = 0x00000002;
  15. const uint ES_CONTINUOUS = 0x80000000;
  16. public static void SleepControl(bool isSleep)
  17. {
  18. if (isSleep)
  19. {
  20. SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
  21. }
  22. else
  23. {
  24. SetThreadExecutionState(ES_CONTINUOUS);
  25. }
  26. }
  27. }
  28. }