开发者

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开发者_C百科 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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜