Detect and prevent/delay windows mobile power off

一笑奈何 提交于 2019-12-13 16:43:29

问题


I have a window mobile application which needs to detect power off and perform some operation before the device shuts down.

I have been able to detect that the device is shutting down using pinvoke to the RequestPowerNotifications win32 api.

However I can not figure out how to block the power off for long enough to run my code.


回答1:


As an application, you can't prevent it unless the OEM has somehow provided a custom API for doing so (and I've never seen it on any WInMo device, only on a few custom CE devices). Whent he power manager is told to suspend, it sends out the notification and begins shutdown immediately. The only subsystems that get an opportunity to delay things are drivers, and they can't call Win32 APIs during that time (it's meant as an opportunity to power off peripherals, save registers, etc).

I also can't say I've ever seen a good reason for an application to ever do this. If a user pushes the power button, they want to power down - not be inhibited by an app. If the OS needs to power down (like due to low power) then preventing it would be a bad thing anyway.




回答2:


As ctacke pointed out: this is dirty. But, you could try SetSystemPowerState( POWER_STATE_ON ); whenever your power notification thread indicates the device is trying to suspend.

http://msdn.microsoft.com/en-us/library/ms920754.aspx

-PaulH



来源:https://stackoverflow.com/questions/2331343/detect-and-prevent-delay-windows-mobile-power-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!