views:

367

answers:

2

Hi all i want to execute code similar to a Interrupt service routine after a timer expires(say print hello after every 10ms) and this is a supplementary activity so it has to be using a timer .So how do i implement timers in vc++

+1  A: 

You want to use the CreateTimerQueueTimer() function. Here is the MSDN sample code.

If you need something that runs on older platforms you're stuck with SetTimer(), which delivers a WM_TIMER message to your WNDPROC. It's a pretty terrible API, so I'd really recommend using the Timer Queue function.

CreateTimerQueueTimer() will spawn a worker thread which does the work of figuring out how much time has elapsed and then call you back when it pops. There are threading implications, but it is much nicer overall, especially if you don't want to have a Window.

jeffamaphone
A: 

Use SetTimer to setup a timer with specified time out. You can either specify a callback method in SetTimer or handle WM_TIMER message. Once done use KillTimer to kill the timer. See this example in MSDN.

Naveen