views:

485

answers:

2

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  A: 

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.

ctacke
Damn I looked there, I didn't find anything. Actually I want the resume event. Specifically for com ports.
nportelli
A: 

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

Joel