How to: Prevent Automatic Power Down

You can override the automatic suspend that occurs when no user input has occurred for a period of time. To prevent automatic power down, call the Windows CE SystemParametersInfo function for each of the three time-out values, SPI_GETBATTERYIDLETIMEOUT, SPI_GETEXTERNALIDLETIMEOUT, and SPI_GETWAKEUPIDLETIMEOUT, as shown in the following code. Your application must call the SystemIdleTimerReset function more frequently than any of the nonzero time-out values.

DWORD batIdle, acIdle, wakeUpIdle, shortestIdle;
TCHAR szOutput[200];

// Get the values.
SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&batIdle,0);
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT,0,&wakeUpIdle,0);

// Determine which is the lowest nonzero value.
shortestIdle=batIdle;
shortestIdle=((acIdle>0)&&(acIdle<shortestIdle)) ? acIdle : (((wakeUpIdle>0)&&(wakeUpIdle<shortestIdle)) ? wakeUpIdle : shortestIdle);

if (shortestIdle==0)
    // If all values are zero, the device can never time out.
    wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power Idle Timeout: %d\nWakeup Idle Timeout: %d\nThe device will not time out."),batIdle, acIdle, wakeUpIdle);
else
{
    // Otherwise, you need to reset the idle timer more
    // frequently than the lowest time-out value.
    wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power
        Idle Timeout: %d\nWakeup Idle Timeout: %d\nYou need to 
        call SystemIdleTimerReset at least every %d 
        sec"),batIdle, acIdle, wakeUpIdle, shortestIdle-1);
}
MessageBox(hWnd,szOutput,_T("Results"),MB_OK);

See Also

Application Hibernation

Handling Low Memory States

How to: Determine Available Memory

How to: Determine Battery Status

How to: Suspend the Device

Managing Variables, Stacks, and Heaps on Mobile Devices

Memory and Power Management

Memory Status and Information

System Out of Memory Dialog Box

Send feedback on this topic to the authors.

© 2005 Microsoft Corporation. All rights reserved.