Category Archives: Microsoft

My experience with .NET Compact Framework

I’ve recently been working with the .NET Compact Framework 3.5 on Windows CE 6.0 for a customer of mine. The .NET Compact Framework is frequently referred to as a sub-set of the full .NET framework. In reality, there are more differences, however.

Overall, the Compact Framework seems to have been crafted with one single strategy; reduced code-/ram-consumption. The garbage collector is therefore working differently. The JIT compiler may also have to compile the same code multiple times because the result of earlier compilations may have been thrown away by the garbage collector. Also, no virtual tables are used. Virtual calls are based on a search-algorithm. Many other differences are documented in Microsoft slide show with the title “MED 301 Developing High Performance Applications with .NET Compact Framework”.

The effect is that many constructs that are acceptable in terms of performance in the full .NET are less optimal in Compact Framework. A virtual method call, for example, has a significantly higher cost (roughly a factor of 1.4) in execution time than a non-virtual call. Of course, it is not a big surprise that a virtual call has a higher cost than a non-virtual call; that’s already known from C++ and also applies to the full .NET framework. The cost is, however, higher in the compact framework.

I helped create a teaser on this while we were working on the project. It’s in danish, I’m afraid, but the solution comes with some interesting measurements that are worth looking at.

Microsoft may well be right that embedded systems typically have less memory than desktops and servers and one therefore needs to be more cautious when coding for embedded systems. But many embedded systems also have significantly less CPU power and are often powered by a battery. So the CPU cycles also matter. And as of this writing, there are no tools available to compile a .NET Compact Framework application to native code for a Windows CE 6.0 device (again, Microsoft’s argument is that the resulting code takes up more space).

If we disregard usability issues, application speed perhaps matters the least in UI-applications. Perhaps Microsoft intended to target their compact framework entirely for UI-applications?

But then, as the range of UI controls, properties, and methods available in the compact framework are far less than those in the full framework, you can only make the most simple UI’s in the compact framework, unless you write your own replacement for Windows.Forms (see e.g. Creating a Compelling UI for Windows Mobile and the Microsoft .NET Compact Framework or Building Graphically Advanced Applications with the .NET Compact Framework 3.5) – and that’s not a small amount of work.

This all makes porting of an application from the full .NET framework to the compact framework non-trivial. Personally, I also feel that the closed-source nature of the .NET framework makes it more difficult to write optimal code.

Add to this that you need both a license for Visual Studio 2005 (to build Windows CE 6.0) and Visual Studio 2008/2010 (to build the .NET application).

All-in-all, my conclusion is; think twice before you embark on the .NET Compact Framework.

Windows Device Emulator vs Windows 7 Firewall

I could find no obvious reason why my Windows 7 firewall was blocking internet access from my Windows Device Emulator to a server application running on the host PC. So, while the Windows CE application was running on the device emulator, trying to get connected with the server application on the host PC, I turned off the firewall, and as I expected, the Windows CE application could all of the sudden connect to the server.

What surprised me a bit, however, was that turning on the firewall again, let the Windows CE application continue to connect/disconnect to the server on the host PC. Now, after each reboot of the host PC, I always start up the device emulator, let the Windows CE application try to connect, start my server, and then turn off the firewall and then on again. It works every time.

Windows 7 Home Premium to Ultimate Upgrade

I had a Windows 7 upgrade (from Home Premium to Ultimate) forced upon me; I was working with a Microsoft Device Emulator and needed to get a .NET Compact Framework application on the emulator to access the network on my Windows 7 host. That required installation of a Virtual PC network driver. Unfortunately, Virtual PC cannot be installed on Windows 7 Home Premium, so I had to upgrade.

To make things worse, an online upgrade is not available where I live. So I had to wait for the upgrade key to be shipped to me.

And when I got the key, things only got worse: I started up Windows Anytime Upgrade and entered the key as requested, and a text kindly informed me that the upgrade would take only 10 minutes. After 1.5 hours, the upgrade was still not done, and there was no network activity, as one could have expected.

I killed the Windows Anytime Upgrade processes and started over again. Same result. Tried to kill as many processes as possible and start over again. Same result. Did a logout and login and started the upgrade once more. Same result. Then decided to restart the machine, but that only made the machine hang during shutdown. After 15 minutes, I pulled the power cord and removed the battery. When I booted the laptop again, the boot manager correctly stated that Windows had not been closed down properly, but I chose to start Windows normally anyway. Windows 7 then started a cycle of 2 or 3 restarts/reconfigurations/updates after which it finally claimed it had upgraded to Windows 7 Ultimate and let me login again.

Needless to say; Windows 7 Ultimate isn’t exactly cheap, so I had expected a smooth upgrade. The experience I had was totally not acceptable!