Keeping the backlight lit in a Windows Mobile app

Monday, December 21, 2009

To keep the backlight on, you may think it makes sense to call SystemIdleTimerReset() repeatedly. (Or at least I thought so.) But this doesn't work on all (most?) phones:

public static extern void SystemIdleTimerReset();

public static void Main(string[] args) {
    // Reset the idle timer every 10 seconds, starting now
    var Timer = new Timer(SystemIdleTimerReset, null, 0, 10000);

    // do useful stuff...

This does work, however:

public static extern void SystemIdleTimerReset();

public static extern IntPtr SetPowerRequirement(
    string device, int deviceState, int deviceFlags, IntPtr systemState, int stateFlags);

public static extern int ReleasePowerRequirement(IntPtr handle);

    PwrDeviceUnspecified = -1,
    D0 = 0, // full on
    D4, // off

public static void Main(string[] args) {
    var Timer = new Timer(SystemIdleTimerReset, null, 0, 10000);
    IntPtr handle = SetPowerRequirement(
        (int) CEDEVICE_POWER_STATE.D1, 
    // do useful stuff...

SetPowerRequirement() forces the system to remain in a higher power consumption state than it otherwise would be in. CEDEVICE_POWER_STATE.D0 is "Full On"; D1 is "Low On" and D4 is "Off." Be sure to ReleasePowerRequirement() when you're done.

The BLK1: is the backlight device name. It's been the same on all the phones I've tested on, but there aren't any guarantees. To find out what the name is on your particular phone, look in the registry in HKLM\Drivers\BuiltIn. There will be a key called Backlight or Frontlight or something similar. The device name seems to be determined by the values Prefix and Index (on my phones these are BKL and 1).

Tags: backlight, wince, winmo | Posted at 22:30 | Comments (3)


Maylene on Sunday, December 27, 2009 at 19:20

I only come here to look at that picture of Morgan with oranges on her head. Does anyone else actually come here?

David on Thursday, December 31, 2009 at 01:28

No, nobody reads this, but hopefully it will be of help for people who are trying to solve similar issues and search for the right keywords?

Alex on Sunday, February 7, 2010 at 12:53

Oh well, I came here and has been extremely helpful.
After couple hours of googling finally this is the only code that works for me.

Thanks a lot.

Add a comment

Email: (optional, not displayed to public)
URL: (do not fill this in — leave blank!)