VBdotnet2005
asked on
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.Stopwat ch sw = new System.Diagnostics.Stopwat ch();
tmr.Interval = TimeSpan.FromSeconds(1);
tmr.Tick += onTimerTick;
tmr.Start();
void onTimerTick(object sender, EventArgs args)
{
textBox1.Text = string.Format("{0:D2}:{1:D 2}:{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();
}
DispatcherTimer tmr = new DispatcherTimer();
System.Diagnostics.Stopwat
tmr.Interval = TimeSpan.FromSeconds(1);
tmr.Tick += onTimerTick;
tmr.Start();
void onTimerTick(object sender, EventArgs args)
{
textBox1.Text = string.Format("{0:D2}:{1:D
sw.Elapsed.Hours,
sw.Elapsed.Minutes,
sw.Elapsed.Seconds,
sw.Elapsed.Milliseconds);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
tmr.Stop();
sw.Reset();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
What is the "big picture" here?