internetmw internetmw - 1 year ago 295
C# Question

How do I reset a dispatcherTimer?

How do I reset a dispatcherTimer?

in my app I start a timer and later on I use the dispatcherTimer.Stop method to stop and the timer stops. I close the application and run it again and the timer doesn't start at zero. How do I set the timer to reset and start at zero?

Answer Source

It looks like what you are calling 'timer count' is:

string etime = DateTime.Now.Second.ToString(); 

Since DateTime.Now is based on the computers realtime clock, you are going to get a different value for seconds based on when you start the program.

You want:

starttime = DateTime.Now;


string etime = (DateTime.Now - startTime).Seconds.ToString(); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download