本文介绍了定时器事件在设备锁定时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了Windows Mobile 6.5应用程序。
我使用了一个计时器事件,此事件将GPS数据插入到一个表中。
它在正常时间正常工作,但是当设备进入锁定/睡眠模式时,当我恢复到应用程序它正在抛出异常并退出应用程序并且它要求时,它无法正常工作重启应用程序。
I have developed Windows Mobile 6.5 application .
i used one timer event ,this event captured the GPS data insert in to one table.
it is working properly in normal time but when device gets locked/sleep mode , It is not working when i ever i get resumed to the application it is throwing exception and exit the application and it is asking to restart the application.
推荐答案
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);
这篇关于定时器事件在设备锁定时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!