Stopwatch has 2 static properties:
.) IsHighResolution and
.) Frequency - the number of ticks - so even if you calculate in ticks you shouldn't assume that its constant (e.g. just divide by 10000), but optain that value from from some api function (note that these ticks may only be valid for the stopwatch object, since other objects might not use the high resolution timer).
(Unfortunately i don't know if high resolution timers have a negative performance inpact)
For example, in my case IsHighResolution is true, so the Frequency the stopwatch is running is 3192270000 ticks/sec. (woot, just figured that out, thats high)
Also, the difference between two DateTimes is a TimeSpan (sometimes things are quite logic
So DateTime is a point in time, and TimeSpan is the difference between 2 timestamps.
You could also write:
Code:
DateTime start = DateTime.Now;
// some code;
DateTime end = DateTime.Now;
// Note that DateTime has an overloaded - operator which returns a TimeSpan:
TimeSpan elapsed = end - start;
Btw, concerning your initial question:
Why don't you use the .TotalXXX methods of the TimeSpan? Actually you could have figured that out with IntelliSense
E.g. elapsed.TotalSeconds > 2.0, or elapsed.TotalMilliseconds > 2000.0
(note: the TotalXXX methods return the result as double, to avoid overflows)
Oh the advantage of stopwatch: Better timing resolution, and "more object oriented" usage - to the 1/10 of a millisecond (the other method only rounds to the nearest 10 ms)