how to implement timer with interval in C++
I am writing a program in C++ where I need to call a function in every 250 ms. It is really easy in C#, but i don't have much idea how to implement that in开发者_JAVA百科 C++.
I would really appreciate if anyone could suggest me the solution.
You might want to look into something called delta timing. This is used in game programming to keep the framerate from going out of control. This is needed because different machines run different hardware and will therefore run at different speeds. So the 250ms that you're looking for maybe x number of cycles on one machine, but when you go to another machine, it may be y number of cycles.
A waitable timer object is a synchronization object whose state is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual-reset and synchronization. A timer of either type can also be a periodic timer.
http://msdn.microsoft.com/en-us/library/ms687012(v=vs.85).aspx
The SetTimer function is used to create a Windows timer.
精彩评论