Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SystemIdleTimerReset (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for SystemIdleTimerReset in other DLLs exists, click on Find References to the right.

.
Summary
This function resets a system timer that controls whether or not the device will automatically go into a suspended state.

C# Signature:

[DllImport("coredll.dll")]
static extern void SystemIdleTimerReset();

User-Defined Types:

None.

Alternative Managed API:

None.

Notes:

To keep a device awake indefinitely, you can use SystemParametersInfo() (also in CoreDll) to query the three idle timeouts SPI_GETBATTERYIDLETIMEOUT, SPI_GETEXTERNALIDLETIMEOUT, and SPI_GETWAKEUPIDLETIMEOUT. Ignoring any values that are zero, use the minimum of these three values as your N, set a recurring timer to fire more often than every N seconds, and call SystemIdleTimerReset() every time it fires. When you're done with your critical operation, kill the timer, and the device will be able to sleep again. I tried this from C# and each idle-timeout value was 0, so I just called SystemIdleTimerReset() every 30 seconds during the critical operation.

You can also look at the configured timeouts at the registry key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power".

Tips & Tricks:

Please add some!

Sample Code:

    /// <summary>
    /// This function resets a system timer that controls whether or not the
    /// device will automatically go into a suspended state.
    /// </summary>
    [DllImport("CoreDll.dll")]
    public static extern void SystemIdleTimerReset();

    private static int nDisableSleepCalls = 0;
    private static System.Threading.Timer preventSleepTimer = null;

    public static void DisableDeviceSleep()
    {
        nDisableSleepCalls++;
        if (nDisableSleepCalls == 1)
        {
            Debug.Assert(preventSleepTimer == null);
                // start a 30-second periodic timer
            preventSleepTimer = new System.Threading.Timer(new TimerCallback(PokeDeviceToKeepAwake),
                null, 0, 30 * 1000);
        }
    }

    public static void EnableDeviceSleep()
    {
        nDisableSleepCalls--;
        if (nDisableSleepCalls == 0)
        {
            Debug.Assert(preventSleepTimer != null);
            if (preventSleepTimer != null)
            {
                preventSleepTimer.Dispose();
                preventSleepTimer = null;
            }
        }
    }

    private static void PokeDeviceToKeepAwake(object extra)
    {
        try
        {
            PlatformUtil.SystemIdleTimerReset();
        }
        catch (Exception e)
        {
            // TODO
        }
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions