您的位置:首页 > 编程语言 > C#

C# pda 数据采集器 防止休眠

2014-08-29 16:05 141 查看
using System.Runtime.InteropServices; 

using Microsoft.Win32;     

  
  [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);  
                preventSleepTimer = new System.Threading.Timer 
        (new System.Threading.TimerCallback(PokeDeviceToKeepAwake), 
                    null, 0, 30 * 1000); 
            } 
        }        

 
     private void FrmMain_Load(object sender, EventArgs e) 
        { 
            DisableDeviceSleep();//在程序创建时开启刷新线程        } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  pda 防止休眠