theboss.robin Posted February 28, 2006 Posted February 28, 2006 (edited) hi,i have a application where i need a timer to intr every 40 msbut i found it was not accurateso i made a program to test ittimer_tick event -----current_time = my.computer.clock.time.millisecondsactual_interval = (current_time-earlier_time)earlier_time = current_timeend sub ---------seems like "user defined interval" is very diff from "actual interval"any userdefined interval from 1-14 makes the timer work every 16msany userdefined interval from 15-34 makes the timer work every 32msany userdefined interval from 35-45 makes the timer work every 47mswhy does the timer not intr exactly acc to interval?or is the program wrong? Edited February 28, 2006 by theboss.robin
TravisO Posted February 28, 2006 Posted February 28, 2006 I don't know what your problem is but you can bet your panties that the .Net time IS accurate.
theboss.robin Posted February 28, 2006 Author Posted February 28, 2006 check this project if you have VB.NET 2005 beta 2 or laterTest.zip
LLXX Posted March 1, 2006 Posted March 1, 2006 any userdefined interval from 1-14 makes the timer work every 16msany userdefined interval from 15-34 makes the timer work every 32msany userdefined interval from 35-45 makes the timer work every 47msThe system timer does *not* have 1ms granularity.See http://www.codeproject.com/system/simpletime.aspLearn to use the CPU's clock counter if you want nanosecond accuracy (e.g. 2GHz CPU = 0.5ns per clock)
HyperHacker Posted March 20, 2006 Posted March 20, 2006 I think in VB6, the Timer control had a 55ms granularity. Not sure if .Net is the same. IIRC, using the API SetTimer() function, you could get as low as 10ms. (Not sure if that's the best it can do, or if VB's overhead just prevents it from being any faster.)BTW, you might want to look at GetTickCount(), which returns the system's uptime in milliseconds. (It's only 32 bits, so it's not really useable if you actually want the uptime, but it's great for timing. Just ensure you don't get caught in a loop waiting for it to be >4,294,967,295, because it never will be.)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now