Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotonically increasing clock in Monotouch

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?

like image 859
Haakon Avatar asked Jan 30 '11 02:01

Haakon


3 Answers

CAAnimation.CurrentMediaTime()

like image 172
Craig Miller Avatar answered Nov 05 '22 04:11

Craig Miller


Try System.Diagnostics.Stopwatch

like image 41
Jason Avatar answered Nov 05 '22 04:11

Jason


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];
like image 1
Daniel Amitay Avatar answered Nov 05 '22 05:11

Daniel Amitay