Friday, December 19, 2014

The Walking HeadlessHost - WP 8.1 Feedback Feature and Zombies

Photo by Juanedc

I was recently working on a rather large Windows Phone app project and came across an issue which took many head scratching hours to figure out. Therefore here's a short heads up if you work on Windows Phone apps with background agents and have those running on Windows Phone 8.1 devices: The WP 8.1's Feedback setting can influence how your background process behaves.

We are talking about a WP 8.0 app with an UI (TaskHost.exe) and a VoIP background agent (HeadlessHost.exe) communicating with each other through an out-of-process RPC server. This approach follows the WP 8.0 VoIP app architecture. When this 8.0 app runs on 8.1 devices I've seen sporadic issues where an instance of the HeadlessHost background process was kept alive when the app was deactivated, for example with fast app switching. When the app get's activated again another instance of the HeadlessHost is started while the previous zombie HeadlessHost is still not dead, so you will end up with two HeadlessHost processes which leads to issues like endless "Resuming..." screens and app crashes when navigating back. This can be seen even without a debugger attached.


If you disable the WP 8.1 device's Feedback setting that issue is gone and the ForegroundLifetimeAgent's HeadlessHost is quickly exited as expected when the UI gets deactivated.
I'm not sure why the Feedback feature is related, my best guess right now: The WP 8.1 Feedback feature gathers telemetry data and therefore keeps the HeadlessHost undead. The weird part is that the HeadlessHost is even undead after a minute and no crash of the background agent happened which means no Watson data should actually have been collected at all or at least not that long.

I'm not sure yet if Silverlight 8.1 apps on 8.1 devices are affected as well or if it's only an issue with 8.0 apps on 8.1 developer unlocked devices. Nevertheless I still wanted to share my experience since it's a rather unknown case and not much information can be found anywhere else so far.

Beyond Kinect for Windows v2 - KinectEx

Kinect for Windows (K4W) and the Kinect v2 sensor are amazing for NUI development and I'm glad that we at IdentityMine have advanced projects where we can leverage this technology.
The K4W SDK already provides lots of nice APIs and a ton of samples to get started. Like usual, there's always more and an SDK can not cover everything but if the official APIs are well built, the open source community is always happy to provide functionality beyond the standard SDK.
One very good open source K4W project is KinectEx which provides some really cool features one often needs when working with K4W v2. KinectEx brings Kinect data recording and playback APIs, so it can be integrated in your own apps, multiple skeleton data smoothing algorithms and much more.
I've contributed a few changes to the project and the KinectEx author is really open for pull requests. Funnily does KinectEx also use one of my open source projects WriteableBitmapEx.

I just wanted to share this very nice open source project and spread the word.
You should definitely look into KinectEx if you are doing any K4W v2 development.