Prevent Pocket PC device from shutting down the app when power is off

How can I prevent my Pocket PC device from closing when I press the power button? I am using C #.

+1


source to share


2 answers


You can use the Microsoft.WindowsCE.Form.MessageWindows class to intercept the Power Button event. This solution will not be portable as the hardware key will be different on different machines.



I recommend, however, that you turn off the power completely. Take a look at my answer in another question here . You can also use openetcf to easily create power-down event handlers and log wake-up events. You have to implement your application logic based on what you are trying to achieve, such as waking up every minute to start a process.

+1


source


You can try changing the power requirements for "BLK1:" which is a black light device. Be aware that the behavior may not be the same for all devices and versions of OS or Vendor specific extensions.

To do this, you can write something like:

    [DllImport("coredll")]
    private extern static IntPtr SetPowerRequirement(string pvDevice, int deviceState, 
                int deviceFlags, IntPtr pvSystemState, int stateFlags);

    [DllImport("coredll")]
    private extern static int ReleasePowerRequirement(IntPtr handle);

      



and call it like this:

    IntPtr handle = SetPowerRequirement("BLK1:", 0 /* D0, Full On */, 1, IntPtr.Zero, 0);
    // Do something that requires the device to stay on ...
    ReleasePowerRequirement(handle);

      

But this is generally not a good practice, and as a result, a backlit device for extended periods can significantly reduce its autonomy.

0


source







All Articles