VB2005 Environment.TickCount not accurate?

G

Guest

Hi All,

I'm reading the Environment.TickCount property after a button click event to
create a basic stopwatch.

If I click the button as uniformly as possible, the resulting gap in
milliseconds seems to be far too even - ie. if I clicked the button 10 times
then there would probably be 2 or 3 intervals with exactly the same reading.
The chances of me being that accurate just by clicking a button are very low,
so either the environment.tickcount property is only accurate to 1/100th of a
second (in which case why is it trying to return a time to 1/1000th) OR my
button_Click event is only called with a set interval OR I am uniquely able
to time my finger movements to the nearest 1/1000th of a second.

If the first case is true - is there a more accurate timer available to me.

If the second case is true, can I increase the priority of button Click
events so they are more accurate?

If the third case is true does anyone have a phone number for Guinness Book
of Records?

I am coding in VB from Visual Studio 2005.

Many thanks in advance.
 
G

Guest

Environment.TickCount shows the milliseconds elapsed since the system started
It's a bit rough, because can't be less than 500 milliseconds.

Use DiteTime.Ticks for this reason

Woof said:
Hi All,

I'm reading the Environment.TickCount property after a button click event to
create a basic stopwatch.

If I click the button as uniformly as possible, the resulting gap in
milliseconds seems to be far too even - ie. if I clicked the button 10 times
then there would probably be 2 or 3 intervals with exactly the same reading.
The chances of me being that accurate just by clicking a button are very low,
so either the environment.tickcount property is only accurate to 1/100th of a
second (in which case why is it trying to return a time to 1/1000th) OR my
button_Click event is only called with a set interval OR I am uniquely able
to time my finger movements to the nearest 1/1000th of a second.

If the first case is true - is there a more accurate timer available to me.

If the second case is true, can I increase the priority of button Click
events so they are more accurate?

If the third case is true does anyone have a phone number for Guinness Book
of Records?

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
M

Michael D. Ober

Environment.TickCount is probably using the system API call GetTickCount().
If so, the interval quantum will be about 55 milliseconds. The primary
clock hardware on a PC only interrupts the processor 18.2 times per second,
or about every 55 milliseconds. For more accurate timing, you will need to
use the MultiMedia API timers. I don't know if they are exposed via the
framework.

Mike Ober.
 
K

Kamujin

Check out this code. http://www.windojitsu.com/code/hirestimer.cs.html

He is using the QueryPerformanceFrequency and QueryPerformanceCounter
API calls to get a more accurate samlpe.

Unless there is something new in the 2.0 framework, this is the
prefered method of obtaining a more accurate sample.

BTW, my GetTickCount() seems to have a resolution of 15ms.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top