zoukankan      html  css  js  c++  java
  • C#程序中防止PPC自动进入待机状态

     [DllImport("CoreDll.dll")]
          private static extern void SystemIdleTimerReset();

          private static int nDisableSleepCalls = 0;
          private static System.Threading.Timer preventSleepTimer = null;

          private static void PokeDeviceToKeepAwake(object extra)
            {
              try
              {
                  SystemIdleTimerReset();
                }
              catch (Exception e)
              {
                    // TODO
                }
          }
           
            /**//// <summary>
          /// 禁止设备自动关闭电源
            /// </summary>
          public static void DisableDeviceSleep()
          {
                nDisableSleepCalls++;
              if (nDisableSleepCalls == 1)
              {
                  //Debug.Assert(preventSleepTimer == null);
                    // 没隔30秒刷新一次计时器
                  preventSleepTimer = new System.Threading.Timer(new System.Threading.TimerCallback

    (PokeDeviceToKeepAwake),
                        null, 0, 30 * 1000);
                }
            }
            /**//// <summary>
            /// 允许设备自动关闭电源
            /// </summary>
            public static void EnableDeviceSleep()
            {
                nDisableSleepCalls--;
                if (nDisableSleepCalls == 0)
                {
                    //Debug.Assert(preventSleepTimer != null);
                    if (preventSleepTimer != null)
                    {
                        preventSleepTimer.Dispose();
                        preventSleepTimer = null;
                    }
              }
          }

            在定时开始时调用DisableDeviceSleep方法就OK了。
  • 相关阅读:
    Hadoop2.x环境搭建
    HDFS序列化
    Hadoop2.x介绍
    eclipse(1)----ubuntu下的安装与配置
    hive与hbase
    mysql----启动报错
    序列化+protobuff+redis
    爬虫学习笔记(2)--创建scrapy项目&&css选择器
    日常随笔
    spark学习(2)--hadoop安装、配置
  • 原文地址:https://www.cnblogs.com/jordan2009/p/1732623.html
Copyright © 2011-2022 走看看