Timer

Am I doing timer correctly? When I click Start, Milliseconds seems not run as fast. It runs like 1, 15, 35, 65 ,etc. It does not start from 1, 2, 3 (real fast here)
 DispatcherTimer tmr = new DispatcherTimer();
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            tmr.Interval = TimeSpan.FromSeconds(1);
            tmr.Tick += onTimerTick;
            tmr.Start();

void onTimerTick(object sender, EventArgs args)
        {
            textBox1.Text = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}",
                  sw.Elapsed.Hours,
                  sw.Elapsed.Minutes,
                  sw.Elapsed.Seconds,
                  sw.Elapsed.Milliseconds);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            tmr.Stop();
            sw.Reset();
        }
VBdotnet2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
You don't understand.
A timer does NOT guarantee to fire at a precise interval, that is a MINIMUM time between the events.  There is also a system minimum which is about 16ms (at least it used to be that some years ago) so it is behaving perfectly correctly.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
Typically anything less than 50 ms in .Net is going to cause problems...

What is the "big picture" here?
0
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
Hi,

Please refer to following links hope they will be helpful to get precise timer
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=570
http://www.codeproject.com/KB/cs/highperformancetimercshar.aspx

thanks
0
AndyAinscowFreelance programmer / ConsultantCommented:
Just one point to make certain you understand.
The values returned from the stopwatch (elapsed property) should be accurate to milliseconds - for normal usage a timer as you are using it is also good enough.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.