65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 C# 保持 PDA 处于唤醒状态

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.30/5 (4投票s)

2007 年 6 月 4 日

CPOL
viewsIcon

30799

使用 C# 保持 PDA 处于唤醒状态

引言

在某些项目中,我们会在 PDA 或袖珍电脑上运行应用程序。 几分钟后,移动设备就会进入休眠状态。 我们需要再次打开设备。 因此,我尝试找到一种解决这个问题并保持 PDA 唤醒状态的方法。

Using the Code

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();
        }

历史

  • 2007 年 6 月 4 日:初始发布
© . All rights reserved.