I need to measure elapsed time several places in my app. I'm therefore looking an API which will give me access to a monotonically increasing clock that is not affected by system clock changes or daylight savings time (something like the number of milliseconds since boot would be adequate).
Some example code to illustrate my problem:
var t1 = SomeClockFunction();
// bunch of code
// ...
var t2 = SomeClockFunction();
var elapsedTime = t2 - t1;
I can't just use the system clock as that could cause wrong measurements if between t1 and t2, the clock is changed by the user or the phone enters/exits daylight savings time.
Objective-C users have access to CACurrentMediaTime() or mach_absolute_time(). What's the equivalent in MonoTouch?
CAAnimation.CurrentMediaTime()
Try System.Diagnostics.Stopwatch
http://www.go-mono.com/docs/monodoc.ashx?link=T%3aMonoTouch.Foundation.NSProcessInfo
NSProcessInfo should be supported by MonoTouch, but hasn't been documented... systemUptime should return the absolute time that the app has been running.
Here's the call in objective-C: (sorry, not familiar with MonoTouch)
NSTimeInterval interval = [[NSProcessInfo processInfo] systemUptime];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With