Is there an event in compact framework that fires on suspend and resume?

半腔热情 提交于 2019-12-12 09:04:24

问题


Or do I have to pinvoke native code?
I don't want the power status...well I do, but I don't want to poll it all the time and would rather have an event fire.


回答1:


No there is not. Generally an application is completely unaware of the power state. When the device suspends, code simply stops executing. When you resume, it starts again at the exact spot it left off.

You can hook into the power management system to get notifications, though be aware that you don't have time to actually react, so it's likely that your code can't actually handle the "going to sleep" event until after it wakes again.

Both These state transitions are exposed in managed functions in the Smart Device Framework's OpenNETCF.WindowsCE.PowerManager class.




回答2:


If you absolutly need to know when a device is suspending the best alternative available is to run your program in unattended mode. Instead of suspending your device will change to the unattended power state. That is your warning that the device wants to suspend. Do what ever work you needed to do before the device suspends then release your unattended request (note, if other programs are requesting unattended mode to then the device may not ever suspend!).

For more information on unattended mode see http://www.codeproject.com/KB/mobile/WiMoPower1.aspx

For an example of getting power change notifications see http://www.codeproject.com/KB/mobile/WiMoQueue.aspx



来源:https://stackoverflow.com/questions/338833/is-there-an-event-in-compact-framework-that-fires-on-suspend-and-resume

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