Maximum Frequency of a Background Timer

Hi everyone. I'm developing a private app which can extract sensor data in a background timer.

To run a timer in the background, I use a small trick: Enabling location update capability in background mode allows my timer to run backgrounded, and it actually works!

My problem is: I choose 100Hz for my repeating timer fire interval in the background. However, the truth is sampling frequency is fluctuating. I've drawn a graph in my computer and the file is at test1.png

As you can see, when app is in the foreground, it works well. Then I switch it to the background, system spends a lot of time (about 1 second) to do the switching. Then when my app is in the background, the frequency starts to fluctuate in [10ms, 100ms] interval. But I hope my timer would run steadily in background too. Then I switch to foreground again, which works perfectly also.

My question is: how can I run a timer steadily in a very big frequency(like 100Hz+)?

Replies

It sounds like to me its related to the CPU when the app is running in the background. Try running in simulator mode and see how the CPU consumption changes.
You're right! The CPU consumption changes significantly from foreground to background, which results in my background timer missing so many scheduled firing times.

Is it possible to enable my app to get enough resource in the background? Maybe set a high priority on my background thread?