zoukankan      html  css  js  c++  java
  • window mobile 防止系统休眠代码

    window mobile 过一段时间就会自动休眠,下面的代码可以禁止机器自动休眠。

    代码
    [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)
                {
                    
    // 没隔30秒刷新一次计时器
                    preventSleepTimer = new System.Threading.Timer(new System.Threading.TimerCallback

                  (PokeDeviceToKeepAwake),
                    
    null010 * 1000);
                }
            }

            
    /// <summary>
            
    /// 允许设备自动关闭电源
            
    /// </summary>
            public static void EnableDeviceSleep(){
                nDisableSleepCalls
    --;
                
    if (nDisableSleepCalls == 0){
                    
    if (preventSleepTimer != null){
                        preventSleepTimer.Dispose();
                        preventSleepTimer 
    = null;
                    }
                }
            }
  • 相关阅读:
    Panorama和Pivot的区别
    Windows phone 全景视图
    在usercontrol里实现导航
    (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
    Windows phone重写返回键
    Windows Phone 8弹窗
    Kotlin 区间的一些小注意
    Kotlin 区间和循环 Loop和Range
    Kotlin when 流程判断
    Kotlin 在kotlin内使用Java的一些注意(长篇)
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/1905756.html
Copyright © 2011-2022 走看看