The Code Project View our advertisersMemory Validator - Faster leak detection, better analysis (Special Launch Offer! $299, Save $100)Advertise on the CodeProject
Home >> System >> General

Timers tutorial
By Nemanja Trifunovic

A tutorial on different kinds of timers 
 Beginner
 VC 4-6, Win95-98, NT4, W2K, MFC
 Posted 11 Jul 2001
 Updated 15 Oct 2001
Articles by this author
Search:
FAQ
What's New
Lounge
Contribute
Message Boards
31 users have rated this article. result:
4.16 out of 5.

[Click here to view the complete article]

[Top] Sign in to vote for this article:     PoorExcellent  
MSDN Magazine - Your guide to Microsoft tools, development environments, and technologies for Windows and the Web.
Premium Sponsor

Click here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASP
Hint: For a faster board use IE 4+, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
 Search (exact phrase)
 View   Per page   Messages since
New threadMsgs 1 to 25 of 31 (Total: 31)[First] [Prev] [Next] [Last]
Subject 
Author 
Date 
  Large Intervals - 5mins to an Hour ??
 Garth J Lancaster 22:41 9 May '02 
  Re: Large Intervals - 5mins to an Hour ??
 Nemanja Trifunovic 10:49 10 May '02 
  Re: Large Intervals - 5mins to an Hour ??
 Garth J Lancaster 19:09 10 May '02 
  Informative Start
 Assyrian 9:42 23 Apr '02 
  Missed another important timer
 rupen 14:02 12 Mar '02 
  Re: Missed another important timer
 Nemanja Trifunovic 14:34 12 Mar '02 
  Re: Missed another important timer
 rupen 14:41 12 Mar '02 
  Error in multimedia timer?
Unconfirmed/Anonymous posting Anonymous 21:48 3 Mar '02 
  About Apc
Unconfirmed/Anonymous posting mister 10:05 17 Jan '02 
  Re: About Apc
 Nemanja Trifunovic 11:23 17 Jan '02 
  Waitable Timer Section Error?
 MarkKozel 14:12 31 Dec '01 
  Re: Waitable Timer Section Error?
 Nemanja Trifunovic 16:47 31 Dec '01 
  unable to use QueueTimer
Unconfirmed/Anonymous posting buddie 0:42 5 Dec '01 
  Re: unable to use QueueTimer
 Nemanja Trifunovic 12:17 5 Dec '01 
  Great article
 Trapper3001 11:47 19 Nov '01 
  Great article but...
 TinBigTX 12:44 14 Nov '01 
  Re: Great article but...
 Nemanja Trifunovic 12:54 14 Nov '01 
  Re: Great article but...
 kommon 16:26 20 Nov '01 
  Re: Great article but...
 Nemanja Trifunovic 16:54 20 Nov '01 
  CThreadTimer footnote
Unconfirmed/Anonymous posting Anonymous 1:27 22 Oct '01 
  Re: CThreadTimer footnote
Unconfirmed/Anonymous posting Anonymous 20:35 1 Mar '02 
  ITaskScheduler
 Manish_Agarwal 0:16 18 Jul '01 
  Waitable timers missing
 Daniel Lohmann 20:18 12 Jul '01 
 
You missed the (for my opinion) most important timer type: the waitable timer kernel object, introduced with Windows NT 3.51 SP5/Windows 98.

A waitable timer is a kernel object, created with CreateWaitableTimer() and then works pretty same as an event that raises signaled state if the time has elapsed or every n intervalls.

The great benefit of kernel timers is that they a) use much fewer system ressources as multimedia timers (which create a THREAD_PRIOROTY_TIME_CRITICAL thread to do the timer operations) and b) you don't need a message loop.

Timer resolution on NT/2k (I don't know and don't care about Win9x) is a global setting and affects most kinds of timers. It can be set by the multimedia timers timeBeginPeriod() call, which calls the native NT NtSetTimerResolution() function exported from ntdll.dll. If you set it to 1 ms, kernel timers are pretty good. In my experience they are even on high load never more than 1-2 ms late. Of course this depends on the priority of the thread that is waiting for the timer to become signaled.

By the way: Newer versions of the platform SDK denote the user data parameter in timeSetEvent() / TimerProc() as DWORD_PTR, not as DWORD, which will expand to a 64bit data type on Win64

Daniel
 
[Reply][Email author][View Thread][Modify][Delete]
  Re: Waitable timers missing
 Nemanja Trifunovic 21:37 12 Jul '01 
  Re: Waitable timers missing
 Daniel Lohmann 10:33 15 Jul '01 
Last Visit: 12:00 Friday 1st January, 1999[First] [Prev] [Next] [Last]
Home >> System >> General
Updated: 15 Oct 2001
Editor: Chris Maunder
Article content copyright Nemanja Trifunovic, 2001
everything else © CodeProject, 1999-2002.
Advertise on The Code Project

DevelopersDexDevGuruProgrammers HeavenTek-Tips ForumsTopXMLVisualBuilder.comW3SchoolsXMLPitstopZVONSearch all Partners