Power Aware Apps – The Easy Way

Making apps power aware, especially through the device Power Manager works, but the code is kind of ugly and a pain to implement.  Once again SDF 2.0 simplifies things:

using System;
using System.Windows.Forms;
using OpenNETCF.WindowsCE;

namespace WindowsCETest
  public partial class MyPowerAwareClass
    public MyPowerAwareClass()
      DeviceManagement.DeviceWake +=
       new DeviceNotification(

      PowerManagement.PowerUp += new DeviceNotification(PowerManagement_PowerUp);

    void PowerManagement_PowerUp()
      MessageBox.Show(“The Power Manager says I’m awake!”);

    void DeviceManagement_DeviceWake()
      MessageBox.Show(“Device notifications say I’m awake!”);

5 thoughts on “Power Aware Apps – The Easy Way”

  1. Hi Chris,

    What a good job you all do with Smart Device Framework! SDF 2.0 sounds and seems really awesome. I’ve already tried this example and other methods and events, and I’m really impressed with all your great effort.

    Just a little comment: I don’t see the real difference between PowerUp and DeviceWake events. I’ve checked help on http://www.opennetcf.org but the behaviour is sometimes strange on my iPAQ h5500. When exactly is fired each?
    Appart from that, just to let you know, I think SetIdleState() method does the same as Suspend() method in my device. It does not switch off the back light of the device. Could be because of being a hellish HP iPAQ, one more time.

    Thanks very much.


  2. Hi Chris,
    My application is having problems with being power aware.
    My idea is to capture wake-up event and when PPC wakes up, show a
    screensaver during x seconds. With your example all works well and DeviceWake event is fired only once, that is, when devices really wakes up.

    I have put it into practice in my application, in my iPAQ h5500 with
    PPC2003 OS, and sometimes (almost always), DeviceWake event fires
    twice. Whye? I’m using SDF 2.0 Beta1. Could be a Beta bug maybe? Or is
    it related to having installed on my PPC both SDF 1.4 and SDF 2.0

    Have you seen this strange problem before? Has somebody suffered this?

    Thanks very much.


  3. The notification doesn’t make it to my handler in time before the system suspends or shutsdown.

    I know the PM doesn’t block for an application that has RegisteredDeviceNotification etc.

    However, I do need this to happen.

    I tried upping the thread priority in my CF app but it still doesn’t always make it in time.

    I did find the spot in my BSP where I could do a SendMessage to trigger and block my OpenNET handler I just don’t how to do it.

    Without source for SDF2.0 it’s difficult for me to figure out how to trigger the handler from unmanaged code.

    Any ideas here.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s