locked
Unattended mode event handler RRS feed

  • Question

  • Hi all,
    I'm trying to write a simple application that has to be run just before device goes into a sleep mode (unattended). I tried to use CeRunAppAtEvent method but there is only NOTIFICATION_EVENT_WAKEUP which is exactly opposite to what I'm looking for. After googling and looking on some older post on this forum I found another method but it needs the process to run constantly and checking what's the current state of the device. I'd prefer to put my process into some system queue as it's done in case of CeRunAppAtEvent and CeRunAppAtTime frunctions.
    The question is: is there any way to handle sleep event - i.e. call the application just before device goes asleep? I'm not interested in SystemIdleTimerReset because I don't want to prevent system going unattended mode, I just want to run small proces before device goes asleep.

    Thanks,
    Pawel
    Monday, August 31, 2009 8:31 AM

Answers


  • Hi,

    Here is a content from codeproject which I think will solve your purpose,

    Use the native function GetDevicePower if you need to monitor or query the power state. Instead of polling the state though GetDevicePower, your program can request notifications for power change events through RequestPowerNotifications.

    If your application needs for the Windows Mobile device to stay in a certain power state, then use SetPowerRequirement to request the power state that your application needs. The OS will ensure that the power state of the device does not drop below what was requested. When the power state is no longer needed, then call ReleasePowerRequirement. To set the power state of a device driver instead of expressing minimum requirements, use SetDevicePower.

    The power state of the system can be set through the native function SetSystemPowerState. The power state for individual hardware items in a Windows Mobile device can be set using SetDevicePower.

    (You can also request that your program be started automatically during certain power change events. See Automatically Starting Your Application on Windows Mobile for more details.)

    When you have an application that needs to run in unattended mode, use the native function PowerPolicyNotify() to inform the OS that you need for the device to continue to run without suspending. This is a reference-count API. For each call to this function with TRUE, you must also call this function with FALSE to ensure the device does not unnecessarily stay in a higher power.

    The full details are at http://www.codeproject.com/KB/mobile/WiMoPower1.aspx?msg=2840882

    Regrads.

    • Proposed as answer by Am_ac1 Monday, August 31, 2009 10:04 AM
    • Marked as answer by Guang-Ming Bian - MSFT Friday, September 4, 2009 2:34 AM
    Monday, August 31, 2009 10:03 AM
  • Hi all,
    I finally figured out there's no slepp event in WM6, so the only possibility right now is to use either NOTIFICATION_EVENT_WAKEUP and do some tasks just after waking up OR run a program that checks constantly current state of device (RequestPowerNotifications function mentioned by Am_ac1)

    Thanks to all for any help,
    Pawel
    • Marked as answer by Pawel Koselski Monday, September 7, 2009 9:21 AM
    Monday, September 7, 2009 9:21 AM

All replies

  • Hi Paul,
    Yes I've seend this thread but (as I understand this) it assumes either to run the process constantly or to use SystemIdleTimerReset but I don't want to alter default device sleep time. I didn't found there anything about handling sleep event, did I missed something?

    Regards,
    Pawel
    Monday, August 31, 2009 8:51 AM

  • Hi,

    Here is a content from codeproject which I think will solve your purpose,

    Use the native function GetDevicePower if you need to monitor or query the power state. Instead of polling the state though GetDevicePower, your program can request notifications for power change events through RequestPowerNotifications.

    If your application needs for the Windows Mobile device to stay in a certain power state, then use SetPowerRequirement to request the power state that your application needs. The OS will ensure that the power state of the device does not drop below what was requested. When the power state is no longer needed, then call ReleasePowerRequirement. To set the power state of a device driver instead of expressing minimum requirements, use SetDevicePower.

    The power state of the system can be set through the native function SetSystemPowerState. The power state for individual hardware items in a Windows Mobile device can be set using SetDevicePower.

    (You can also request that your program be started automatically during certain power change events. See Automatically Starting Your Application on Windows Mobile for more details.)

    When you have an application that needs to run in unattended mode, use the native function PowerPolicyNotify() to inform the OS that you need for the device to continue to run without suspending. This is a reference-count API. For each call to this function with TRUE, you must also call this function with FALSE to ensure the device does not unnecessarily stay in a higher power.

    The full details are at http://www.codeproject.com/KB/mobile/WiMoPower1.aspx?msg=2840882

    Regrads.

    • Proposed as answer by Am_ac1 Monday, August 31, 2009 10:04 AM
    • Marked as answer by Guang-Ming Bian - MSFT Friday, September 4, 2009 2:34 AM
    Monday, August 31, 2009 10:03 AM
  • Am_ac1,
    Thanks for exhaustive explanation. I don't need my device to stay in certain power mode. I'm working on a simple application which locks the keypad when the device goes asleep. That's the reason I want to handle "sleep" or "going unattended" event - because that's the moment I want to lock the keypad. From your post the most interesting for me sounds:

    (You can also request that your program be started automatically during certain power change events. See Automatically Starting Your Application on Windows Mobile for more details.)

    but the link seems to be broken, I get HTTP 403 error. Could you please verify this link? Thanks in advance!

    Pawel
    Monday, August 31, 2009 11:41 AM
  • So filtering out what you do not need RequestPowerNotifications will tell you when device is goes to sleep mode. And here is when you can lock the keypad.... The link is not working for me as well. Hope this helps.

    Monday, August 31, 2009 12:57 PM
  • Hi all,
    I finally figured out there's no slepp event in WM6, so the only possibility right now is to use either NOTIFICATION_EVENT_WAKEUP and do some tasks just after waking up OR run a program that checks constantly current state of device (RequestPowerNotifications function mentioned by Am_ac1)

    Thanks to all for any help,
    Pawel
    • Marked as answer by Pawel Koselski Monday, September 7, 2009 9:21 AM
    Monday, September 7, 2009 9:21 AM