opcon's picture

Timed events

Hey all,

Just a quick question, if I wanted to have events happen after a certain time has elapsed, what would be the best way to do it? At the moment I'm thinking of using the .NET stopwatch class, and checking each update frame to see if the requested amount of time has passed, if so then do the action. While this doesn't provide exactly precise measurements, it is reasonably good.

The only other way I could think of would be to increment a variable each update, and set a certain threshold for it. This would be slightly more accurate, but more work (e.g. converting the thresholds), and if I ever changed the update frequency it would break.

So, should I go with using the stopwatch class? Or is there another way that I'm not thinking of?

Thanks, opcon


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Comparing the Timer Classes in the .NET Framework Class Library. Stopwatch is a reasonale do-it-yourself approach but note that it won't necessarily be accurate over large periods of time.