hi
i need to measure time between 2 button press
in Windows-CE C#
how do do it ?
thank's in advance
hi
i need to measure time between 2 button press
in Windows-CE C#
how do do it ?
thank's in advance
Define a variable when the button is clicked once to NOW(). When you click a second time, measure the difference between NOW and your variable.
By doing NOW - a DateTime variable, you get a TimeSpan variable.
DateTime? time;
buttonClick(....)
{
if (time.HasValue)
{
TimeSpan diff = DateTime.Now.Subtract(time.Value);
DoSomethingWithDiff(diff);
time = null;
}
else
{
time = DateTime.Now;
}
}
DateTime.Now may not be precise enough for your needs. http://blogs.msdn.com/b/ericlippert/archive/2010/04/08/precision-and-accuracy-of-datetime.aspx (Short short version: DateTime is extremely precise, DateTime.Now -> not so much.)
If you want better precision, use the Stopwatch class (System.Diagnostics.Stopwatch).
Stopwatch watch = new Stopwatch();
watch.Start();
// ...
watch.Stop();
long ticks = watch.ElapsedTicks;