On .NET Compact Framework

by

This is a warning!
Just because you are a Java developer doesn't mean you can steer clear of other technologies. I got a taste of this when I was asked to work on a compact framework application in January 2009. .NET CF is a stripped down version of its desktop equivalent, meant for handheld devices like PDAs and Smartphones.
Since I am no stranger to CF ( my final year project had a module on the PDA), I was at home, well aware of CF quirks and shortcomings.
Was it fun? Initially, yes. But as you keep going on, you come to know it limitations, and that is irritating. And even though the guys at Microsoft Forums try to help you out, creating a CF application with a snazzy enough GUI is still difficult.

Since application designers need to have some idea of what's possible with CF, and what might stretch the device, here are my random thoughts:

  1. Do not mistake a PDA for a desktop machine. Its computing abilities are limited.Take a look at how CF manages its memory and you'll know what I'm talking about. Read http://blogs.msdn.com/stevenpr/archive/2005/12/12/502908.aspx The interesting part? "The .Net Compact Framework CLR manages the memory in the per-process 32 MB virtual address space on behalf of the developer." This just means that 32 MB is all you've got, and there is now way to increase the memory available to your application. (Believe me, I tried. I naively thought that increasing the RAM available to the emulator will somehow magically grant my application more space to play around, it didn't.) What does this mean? In my case the PDA application was downloading lots of information(MBs) from a web service in xml format, but would get an out of memory exception when trying to parse the xml. So, we had to strip the xml down to the barest, remove redundant information and trim down the tag names.
  2. Plan in advance if you want a striking GUI. The controls in the toolbox are just not good looking enough, and sometimes lack inbuilt functionality. For instance, a common requirement is a customized datagrid, with columns having checkboxes, combos and what-nots. In my case, we wanted a column of icons. For the sample app on how to implement a customized datagrid, look for the Compact Framework team blog, posts by Ilya Tumanov. I'm still struggling with the GUI. You've people used to the iPhones and Mac GUI's, so you cant just give them an app that seems developed for people from the last decade. I've heard of a technique called Alpha Blending that promises to improve the look substantially, but haven't found the time to experiment yet.
  3. Work with the latest tools. The latest CF version is 3.5 which is only available with VS 2008. The last version was 2.0 on VS 2005. But where the CF 3.5 really takes off is the presence of a testing framework for mobile devices. Check out the "How do I videos for Mobile devices." Also available are the PowerToys, which help you with monitoring your device's performance in terms of memory. I've used the Remote Performance Monitor also. If you want a good free profiler for mobile apps that works on on CF 2.0 also, try the EQATEC profiler for .NET apps, but its limited to letting you know the time taken by your function calls, nothing about the memory. There's also a tool around, called the Hopper, which checks your application's responsiveness to random clicks, something the CF team at Microsoft used internally and have now released for all of us. Another ramdom tip: VS 2008 supports 2.0 apps, and an application can be upgraded from 2.0 to 3.5 easily, but once you upgrade from 2.0 to 3.5, you can't just "downgrade" back to 2.0, so make a backup.
  4. P/Invoke. These are system level calls which you'll need if you want to interact with device, say play a sound or simulate a keyboard click. Some things still need you to talk to the device directly. Take a tutorial on P/Invokes, it'll come in handy.
  5. OpenNetCF. These guys have a bunch of dll's, called SmartDeviceFramework, ready to provide you some extra functionality. When Microsoft disappoints, this is the place to search for answers.