High-resolution timer in MacOS - macos

I'm looking for high-resolution timer API in MacOS. In Windows there is Windows Multimedia Timers API that allows to fire events with resolution of 1ms. Is there analog in MacOS?
Edit 1:
I've tried CFRunLoop timers and it seems it gives appropriate resolution. But CFRunLoopRun method blocks current thread and this is not good. I want just start timer and continue with my following code. Is it possible? At now it seems MacOS lacks API for high-resolution timers that can give steady firing intervals.

Related

SystemEvents.SessionLock/SessionUnlock OR WM_WTSSESSION_CHANGE does not get sent on a 64 Bit Winform with Video

We have a 64 Bit .Net Application which is a Windows Form. The UI has a Live Video display which shows every Frame from a USB Camera using a delegate eventhandler. Frames are sent to this UI at 60 frames /sec.
We have a need to stop the Live update whenever Windows Locks out due to the screen saver settings.
Code is all in C#.
We do know that the SystemEvents.SessionLock/Unlock does the trick for us. OR we could also use the WM_WTSSession_CHANGE through the WTSRegisterSessionNotification API's. Either way it is supposed to do the same work of letting the UI know that Windows has Locked or Unlocked.
All good so far.
The issue is when the Live Video is being updated, the SessionChange Events never gets to the WndProc() method or the SystemEvents SessionSwitch eventhandler.
If I stop the Frame updates, then the events work perfectly fine.
Yes the Frames being updated are on the GUI Thread using the InvokeRequired checks.
Result is the App crashes when Windows Locks out, because we didn't process the events in 5secs(MS recommendation). I have tried many options of getting it to process the events with some luck however its very inconsistent.
This is a kind of threading issue where the Frames updating is not allowing the Session events to be processed.
Any ideas on how we can look into these session events before Frame updates? or on how do we solve this so the UI can process the Session events?
Your suggestions are much Appreciated.
Update:
If I force a lock(click Ctrl+Alt+Del) and log back in the Session Events are received. Just does not happen on Screen saver Lock.

Android Wear: implementation of standard Timer App

I'm trying to implement the same app as standard Timer app (for learning purposes).
Is it available sources of standard Timer app installed on Android Wear?
How to implement starting and displaying Activity from Sleeping Mode. Like green screen in Timer app, that appears when timer reach zero. (the problem: flags FLAG_TURN_SCREEN_ON, FLAG_KEEP_SCREEN_ON, FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD in onCreate method don't help to cancel Sleep Mode Screen and display target Activity to user).
Cheers!

OS X: Energy Efficient Web Service Calls in Background

What is the most energy efficient way to call a web service in the background under OS X?
On iOS I would use the fetch background mode, but I haven't seen anything similar for OS X. Right now I have an NSTimer that fires every 25 minutes, but the schedule gets messed up if the device goes to sleep while the timer is waiting to fire.
Before I write some code to deal with sleep/wake I wanted to see if OS X has a better mechanism for my use case. I have not found anything in the docs.

NSTimer in Cocoa (MAC) app

I am working on a timer application where i have used 5-6 timers running at one time, I need all the timers running at the same time. For ex. calculating a time, updating the UI etc.
But this is hangs my app, After some time, its started not responding.
Then i quit the app and re-launch but this time i didn't start the timer (Only one timer is running) and i found that application is fine this time.
I think the issue is due to usage of multiple timers at the same time as these timers are updating the UI frequently after every seconds. I need to updated my label with the updated time, but how i could do this without using an NSTimer. If NSThread is an option then please give me an example to achieve this.

Track Accelerometer under lock screen

Is it possible to track the accelerometer value while under the lock screen?
I managed to write a simple application which counts from 1 up to 100 using a timer which fires an event on which I increment a counter.
But when I use register a handler for the ReadingChanged event of the accelerometer it will not be fired anymore once the screen has been locked. Even if I unlock the screen again I will have to readd my handler.
the msdn documentation tells on the one page:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff941090(v=vs.105).aspx
"Valid reasons to disable idle detection in Windows Phone OS 7.1 applications include ones where core functionality continues while the phone is locked (for instance, an exercise tracking app)"
but the sensor api also tells:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202968(v=vs.105).aspx
"The Sensor APIs cannot be used while the application is running under the lock screen. For more information, see Idle Detection for Windows Phone. The Sensor APIs also cannot be used in background agents. For more information, see Background Agents Overview for Windows Phone"
I hope they will change the api soon, because of that it is not possible to write any good sleep tracking / sport tracking applications ... :(
I was helping a guy with this a couple of days ago. He had an app that tracks GPS and accelerometer data under lock screen.
Turned out the app accelerometer data stopped tracking when under manual or auto lock screen.
There may be an issue here to be looked into.
Under lock screen it is a good idea to minimise power usage... disable all uncessary code, like ui updates. My understanding of one the motivations for idle detection and running under lockscreen being opened up during CTP was in response to a lot of feedback from developers of map/tracking apps that basically need this for their app to be of any use.
I'm not sure of the usage case where you'd want to use the accelerometer under the lock screen.
Apps typically run under the lock screen when you need them to do something when you're not interacting with the device. e.g. playing music or downloading a large file.
If you wanted accelerometer data I'd assume that the device is being held and, therefore, presumably, looked at. Given this, why would you therefore want to run under the lock screen?
That being said, if you had a good reason to do so, you should still be aware that:
when your application runs under a locked screen, it ... must minimize
power usage
(from the Marketplace Certification Requirements.)
In my understanding, reading values from sensors is not minimizing power usage.

Resources