Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

VB2005 Environment.TickCount not accurate?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Woof - 01 Mar 2006 12:39 GMT
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.
Michael Nemtsev - 01 Mar 2006 12:56 GMT
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

> Hi All,
>
[quoted text clipped - 17 lines]
> If the third case is true does anyone have a phone number for Guinness Book
> of Records?

Signature

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

Michael D. Ober - 01 Mar 2006 14:15 GMT

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.

> Hi All,
>
[quoted text clipped - 21 lines]
>
> Many thanks in advance.
Kamujin - 02 Mar 2006 13:55 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.