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 ?