-1

I am working on an analog clock app, that has the accuraty of an normal clock. Instead of displaying the current time it has to display the time starting from a given time. I used a timer event handler that is triggered every second.

protected void Timer_Tick(object sender, EventArgs e)
{
    DateTime CurrentTime = DateTime.Now;

    TimeSpan ElapsedTime = m_PrevCurrentTime.HasValue ? CurrentTime - m_PrevCurrentTime.Value  : TimeSpan.Zero;

    Time += ElapsedTime;

    // Update clock.
    :

    m_PrevCurrentTime = CurrentTime;
}

ElapsedTime however is never exactly 1 second, so the clock runs not exact. Is there a better approach ?

Ron
  • 85
  • 5

1 Answers1

0

You can never get the exact clock value at least on Windows. The ordinary resolution is about 15 ms. Meaning you get the same value for 15 ms in a row if you read the value.

You can get more information in this question.

It is possible to reduce the resolution to a lower value and you can find details in the same question I referenced above.

Community
  • 1
  • 1
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207