Microsoft KB Archive/811420

= Timer Resolution Changes After the System Resumes from a Suspended Power State =

PSS ID Number: 811420

Article Last Modified on 7/15/2003

-

The information in this article applies to:


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Server SP1
 * Microsoft Windows 2000 Server SP2
 * Microsoft Windows 2000 Server SP3

-



SYMPTOMS
You can use the timeBeginPeriod function in the Winmm.dll file to start a timer with a specified resolution. When you use the timer, and you put the system into a suspended power state and then resume the system, your timer resolution is changed back to the system default after the system resumes. This resolution change may cause your application to stop responding.



CAUSE
Timers that are provided by Winmm.dll are supported by the system clock. The system clock generates a timer interrupt at a fixed interval. However, this interval can be changed by the system. When you call timeBeginPeriod with a new resolution, the system changes the interrupt interval to the new specified value.

When the system resumes from a suspended power state, a reinitialization of the system clock reverts the interrupt interval to the default value (typically 10 milliseconds), and therefore, the timer's resolution is changed.



WORKAROUND
To work around this issue, follow these steps:
 * 1) Call the timeEndPeriod function to clear the timer resolution in the WM_POWERBROADCAST / PBT_APMQUERYSUSPEND message handler of the main window.
 * 2) Call timeBeginPeriod to restore the timer resolution in the WM_POWERBROADCAST / PBT_APMRESUMESUSPEND message handler of the main window.



MORE INFORMATION
In step 1 of the &quot;Workaround&quot; section, if the application contains nested timeBeginPeriod and timeEndPeriod calls before suspension, it must call timeEndPeriod to clear the highest timer resolution. If the highest resolution is set by multiple timeBeginPeriod calls, timeEndPeriod must be called the same number of times as timeBeginPeriod, as in the following sample code: // Some resolutions are set. timeBeginPeriod(2); timeBeginPeriod(1); timeBeginPeriod(1); timeBeginPeriod(3);

// Application …… // Handle the suspend message. WM_POWERBROADCAST / PBT_APMQUERYSUSPEND message // Call timeEndPeriod(1) two times to clear the highest resolution. timeEndPeriod(1); timeEndPeriod(1); ……

// Handle the resume message. WM_POWERBROADCAST / PBT_APMRESUMESUSPEND message // Call timeBeginPeriod(1) two times to resume the highest resolution. timeBeginPeriod(1); timeBeginPeriod(1);

// Application …… timeEndPeriod(3); timeEndPeriod(1); timeEndPeriod(1); timeEndPeriod(2);

Keywords: kbprb KB811420

Technology: kbwin2000Search kbwin2000Serv kbwin2000ServSearch kbwin2000ServSP1 kbwin2000ServSP2 kbwin2000ServSP3

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.