views:

237

answers:

2

I have a function in C++ that needs to be called after a period of time and this task is repeated. Do you know any built-in function or sample code in Win32 or pthread?

Thanks,

Julian

+5  A: 

How about SetTimer.

  1. Create a wrapper function to use as the callback for set timer.
  2. Wrapper function calls your function.
  3. After your function finishes, wrapper function calls SetTimer again to re-set the timer.
Eric Petroelje
+1  A: 

Just as a side note, I hope that you aren't doing something in code which could be done via the OS. (I don't know enough about your requirements to say, but I thought I'd point it out).

Things such as task-scheduler (windows) are made for scheduling recurring tasks, and they often do a better job than hand-rolled solutions.

brad