最近,遇到一個需求,就是每 30 秒更新一次 GPS 位置,在測試過程當中,發如今系統待機後,更新GPS 位置就不能正常運行了,搜索後,發現以下的解決方案,實際應用了以後,有效,贊!!!
http://stackoverflow.com/questions/873816/keep-windows-mobile-app-running-in-standby-mode
public const int PPN_UNATTENDEDMODE = 0x0003; public const int POWER_NAME = 0x00000001; public const int POWER_FORCE = 0x00001000; [DllImport("coredll.dll")] public static extern bool PowerPolicyNotify(int dwMessage, bool dwData); [DllImport("coredll.dll", SetLastError = true)] public static extern IntPtr SetPowerRequirement(string pvDevice, CedevicePowerStateState deviceState, uint deviceFlags, string pvSystemState, ulong stateFlags); [DllImport("coredll.dll", SetLastError = true)] public static extern int ReleasePowerRequirement(IntPtr hPowerReq); public enum CedevicePowerStateState : int { PwrDeviceUnspecified = -1, D0 = 0, D1, D2, D3, D4, } // Keep the GPS and device alive: PowerPolicyNotify(PPN_UNATTENDEDMODE, true) IntPtr gpsPowerHandle = SetPowerRequirement("gpd0:", CedevicePowerStateState.D0, POWER_NAME | POWER_FORCE, null, 0); // Call before exiting your app: ReleasePowerRequirement(gpsPowerHandle); PowerPolicyNotify(PPN_UNATTENDEDMODE, false);