SystemParametersInfo and Suspend Mode Timeout

P

Peter B

Hi!

I am trying to get the suspend mode timout values using SystemParametersInfo
using this code:

[DllImport("coredll.dll", EntryPoint="SystemParametersInfo")]
internal static extern int SystemParametersInfoSuspend (
int uiAction,
int uiParam,
out int pvParam,
int fWinIni );

public static string DisplayIdleTimeouts()
{
int iBatIdle = -1, iACIdle = -1, iWakeUpIdle = -1;
int res1, res2, res3;
string msg = "";

try
{
res1 = SystemParametersInfoSuspend( SPI_GETBATTERYIDLETIMEOUT, 0, out
iBatIdle, 0);
res2 = SystemParametersInfoSuspend( SPI_GETEXTERNALIDLETIMEOUT, 0, out
iACIdle, 0);
res3 = SystemParametersInfoSuspend( SPI_GETWAKEUPIDLETIMEOUT, 0, out
iWakeUpIdle, 0);

if( res1 != 0 && res2 != 0 && res3 != 0 )
{
msg = "Battery Idle Timeout: " + iBatIdle.ToString() +
"\nAC Power Idle Timeout: " + iACIdle.ToString() +
"\nWakeup Idle Timeout: " + iWakeUpIdle.ToString();
}
return msg;
}
catch( Exception exc )
{
return exc.Message;
}
}

The results of the function calls are all 1, BUT the value of dwBatIdle,
dwACIdle, dwWakeUpIdle are all set to zero. The device is set to turn off
after three minutes when running on battery power.

[GWES problem?]
In
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncenet/html/WinCEFAQ.asp I
read that the SPIs I am trying to get the value of, will be 0 if GWES is
disabled, how would I know this?

a.. Disabling GWES suspend management causes attempts to set the GWES
time-out values using SystemParametersInfo to fail with
ERROR_RESOURCE_DISABLED. This affects the SPI_SETBATTERYIDLETIMEOUT,
SPI_SETEXTERNALIDLETIMEOUT, SPI_SETWAKEUPIDLETIMEOUT parameters. The
SPI_GETBATTERYIDLETIMEOUT, SPI_GETEXTERNALIDLETIMEOUT,
SPI_GETWAKEUPIDLETIMEOUT parameters will all read 0.

Does this mean I cannot get the timeout information via
SystemParametersInfo??

[Goal]
My main goal here is to stop auto suspend from happening while long I/O
operations are in progress. I do have a solution to this by using
SystemIdleTimerReset. But since I cannot receive the current suspend mode
timeout I have to set the timer that calls to Reset method to a low enough
value (less than 30s).

[DllImport("coredll.dll", EntryPoint="SystemIdleTimerReset")]
internal static extern void SystemIdleTimerReset();

public static void ResetIdleTimer()
{
SystemIdleTimerReset();
}

timer1.Interval = 28000; // Tick every 28s

private void timer1_Tick(object sender, System.EventArgs e)
{
ResetIdleTimer();
}

[Resources]
Another google thread http://tinyurl.com/2r48z with the idea of using
SystemIdleTimerReset.

MSDN Preventin Automatic Power Down:
http://msdn.microsoft.com/library/d...e_ppc/htm/programming_pocket_pc_2002_lfyy.asp

MSDN SystemParametersInfo:
http://msdn.microsoft.com/library/d...us/wceui40/html/cerefSystemParametersInfo.asp

I'm satisfied with this solution, but I still wonder why I can't get the
power information with SystemParametersInfo...

Any ideas and/or suggestions are most welcome!

thanks,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top