Windows .NET Development on Mac OSX

I use Windows at work so for some variety I have moved to a Mac at home. The 2010 Mac Mini is a decent little machine with the RAM upgraded to 4GB.

For Windows development you need Visual Studio, which means running Windows on your Mac. Bootcamp is one way of doing this, but then you lose all the benefits of OSX as your host OS. The secret is of course Parallels Desktop which allows you to run Windows virtualized on your Mac.

Using Parallels Desktop for Windows Development

It took a couple of tries to get this working decently.

  • Install Parallels Desktop
  • Get a Windows 7 32bit ISO image from MSDN (or a retail copy of course)
  • Set up a new Virtual Machine, specifying your Windows 7 ISO to install from
Screen shot 2010-12-16 at 9.19.16 PM.png
  • Select “Like a Mac” so the application integration gets automatically set up
  • IMPORTANT: For best performance, place the virtual machine on a separate drive. I get good results with an external USB2.0 Hard Drive but Mac Pro owners can put this on an internal disk. The built in hard disk of the Mac Mini is only 5400rpm which will be a real bottleneck when running OSX and Windows off the same disk. (You can of course use Parallels to run Windows off your Bootcamp partition – this will be slow too if the partition is on the same physical disk as OSX).
  • Allow Parallels to install Windows automatically. It will select the default settings during installation and input your product key. You will eventually end up with a nice Windows 7 desktop inside a Parallels window.
Screen shot 2010-12-16 at 9.27.33 PM.png
  • Parallels will automatically map your Desktop, Documents, Pictures, Music and Download folders to Windows’s equivalents, meaning you will see the same files on the Mac and Windows desktops.
  • Install Visual Studio 2010. You can mount the ISO in the Parallels Virtual Machine settings. A couple of restarts (of the VM) later and it is installed.
  • You will notice that running applications in the Windows VM show up in the Dock. You can even right click and pin the applications to the Dock. Parallels will start the virtual machine and launch the application.
  • Click the Coherence button in Parallels and Windows will be integrated with OSX. Launching Visual Studio 2010 from your pinned dock icon will give you Visual Studio 2010 with the same appearance and window behaviour as a standard Mac app:
Screen shot 2010-12-16 at 9.34.30 PM.png
  • You are now ready to develop Windows applications from OSX. Parallels has GPU acceleration so even WPF applications are not too bad.

Advanced Tips

  • Give the Windows 7 Virtual Machine enough RAM, but not enough that OSX will start paging. With 4GB of RAM, you can afford to give the VM 1GB. Remember: you are only going to run Visual Studio on Windows 7. All your other apps; browsers, Photoshop, Skype etc, will run in OSX.
  • Activate the “Pause Windows when no applications are open” setting under Applications in the Windows 7 VM settings. This means that the virtual machine will pause and give the memory back to OSX when no applications are running.
  • Be aware that your Documents folder on Windows is now a network drive, with all the security differences this brings. .NET will be strict about this in some cases (I hit this problem when running a custom content processor for XNA, which cannot be loaded from network drives) If you hit security problems, you need to set the \\.psf\ network drive to FullTrust for .NET. Run this command from a command prompt in Windows and restart Visual Studio:
C:\Windows\Microsoft.NET\Framework\v2.0.50727> CasPol.exe -pp off -m -ag 1.2 -url \\.psf\* FullTrust
  • Make sure that while you backup your Documents folder and Visual Studio projects with Time Machine, don’t backup the drive that the Windows Virtual Machine hard disk is on or you will run out of backup space very quickly. Parallels also has an option to make sure that this does not happen.

 


That upgraded WPF 4.0 Text rendering again

Just to hammer the point home about how important it is to upgrade to .NET 4.0 if you are using WPF, here are some comparison screenshots of the text rendering in WPF 3.5 and 4.0:

wpftext.png

Pay attention to the difference between the text rendering on lines 2 and 3.

Line 2 shows the new Display formatting mode available in WPF 4.0. This renders the text the same way as the rest of Windows – the shape of the font is distorted so that lines fall on pixel boundaries. For small text this should be used for consistency with the rest of Windows or users will most likely complain that your text looks “blurry” (even though it is technically rendered correctly). Large font sizes or high DPI screens can stick to the standard WPF rendering mode.

Line 3 shows what Japanese Windows XP users will see if they use your application as they don’t have Meiryo installed. In WPF 3.5, Asian text is a mess at small font sizes because WPF 3.5 does not support bitmap fonts – instead it scales down the large vector font data in the font file. WPF 4.0 supports bitmap fonts so that Japanese text now is rendered the same way as the rest of Japanese XP.

It is worth being reminded that it took Microsoft themselves to dogfood WPF 4.0 when developing Visual Studio 2010 before these problems were solved.


Evernote has no patience, drops WPF over fixed issues

Much noise has been made about Evernote’s new Windows client. For version 4, they dropped WPF/.NET and released a C++ native application.

They were pretty damning with their reasoning:

Evernote 4 is a major departure from Evernote 3.5 in every way. While 3.5 added tons of great new features, there were some problems we simply couldn’t fix: the blurry fonts, slow startup times, large memory footprint, and poor support for certain graphics cards were all issues that the technology behind 3.5 (Windows .net and WPF) was incapable of resolving. As a result, we ended up chasing down platform bugs rather than adding the great features our users wanted.

So we decided to start over from scratch, with fast, native C++ that we knew we could rely on. As you’ll see, the results are amazing. This new version will set a foundation for rapid improvement.

Evernote 4 is designed to give you a great experience on any computer that you use, whether you’re on a netbook, a five year old Windows XP machine or a super fast top-of-the-line Windows 7 computer.

On our test hardware, Evernote 4 starts five times faster, and uses half the memory of Evernote 3.5.

 

You cannot make statements like “issues that the technology behind 3.5 … was incapable of resolving” without providing more information on the problems they faced and the solutions they tried. For all we know, their Windows client development team could have tripled in size to get the native version out the door.

Evernote 3.5 was a textbook example of reasons to immediately upgrade to .NET 4.0 if you are building WPF applications. Visual Studio’s UI layer is now in WPF, presumably after fixing all these issues.

“The text is blurry”

This is fixed in WPF 4.0, which can render text almost exactly as Windows does if developers request it. The standard behaviour is a DPI-independent accurate representation of the font on the screen (the same way OSX renders text and also the reason why text is “blurry” on Macs).

This is a one-line fix in .NET 4.0, just apply TextOptions.TextFormattingMode=”Display” to your root XAML element. Asian text will also now use bitmap fonts so customers on Japanese XP machines will now get consistent text rendering between your app and their vintage OS (of course Vista/Win7 should be using Meiryo).

“The download size is too large”

The runtime for .NET 3.5 is 65MB or so. .NET 4.0 has reduced this to a 28MB download. Ironically, the Evernote 4.0 installer is 40MB – most likely larger than bundling the .NET 4.0 runtime in the installer of 3.5. Users with .NET 4.0 already installed would have got an even smaller download as the installer would not download the runtime.

Evernote 4.0 appears to include Chromium (the Chrome web browser base), Foxit Reader’s PDF libraries, SQLLite and libxml which could be replaced with the built in Web Browser control, XPS rendering, SQLCE and built in XML libraries of .NET 4.0.

“It uses too much memory”

If your application has hundreds of threads and handles complex local operations, it will require memory. Evernote’s statement about version 4.0 using “half” the memory of the managed 3.5 version is pretty damning considering that the application is not very complicated.

While you may never be able to match the memory consumption of a “native” application in .NET, there are some things you need to know to improve your memory use:

  • Use .NET 4.0 as it has background garbage collection
  • Keep your visual tree small (no endless nested Grids in XAML)
  • Virtualize your ItemControls! This might be the most important issue. You cannot bind a XAML WrapPanel to 1000 images without Virtualization and expect scrolling to be smooth or your memory consumption to be low.
  • Use the ThreadPool and Background Workers instead of manually creating threads. ThreadPool-based tasks intelligently carry out the number of simultaneous tasks based on the number of processor cores you have. Allowing your code to create and infinite number of threads is a recipe for disaster as each thread needs its own stack space of at least 1MB. Ideally use .NET 4.0s new parallel programming and async functions.
  • Read the correct memory numbers in Task Manager (Private Working Set).

“The application is slow to start up”

Managed applications do not have to start slowly. A new application from a VS template will start up instantly – it is when you start adding references to other libraries, interop hooks and modules (for composite apps) that startup time starts dropping. Perhaps the most important thing to do is use NGEN to generate a native version of your application at install time, instead of waiting for the JIT compilation when the user launches the application. The application will slow down when loading modules for the first time if they have not been pre-compiled. There is some great information on improving start up times on MSDN, as usual.

In general, try to show some part of your application immediately. A splash screen might be okay for application start up times of less than a few seconds, but there is no reason why the main window can not be displayed and relevent data start loading in the background. This is mainly a perception issue. If you only show your main window after loading all data that your application could possibly need ever, of course start up will appear to be slow.

Did Evernote even try .NET 4.0?

The .NET development community is waiting for some sort of postmortem from the Evernote team. Most of the above problems would have been solved by upgrading to .NET 4.0 and running some decent profilers on the executable.

Rewriting your application natively will no doubt use less memory and start up faster, but it will also look worse, take longer, be more expensive to develop and your UI will break when high DPI screens start to be used. Portability is not a reason: if you want an application to work on Windows/Mac/Linux/iOS/Android, you write a web application.

If you want an example of an amazing WPF 4.0 application designed for the Windows platform, check out MetroTwit.


Free Cloud-based online Microsoft Money using Dropbox

I have used Microsoft Money to manage my finances for coming up 6 years now and still find it the best personal finance app around. The last version in the UK was 2005 after Microsoft cancelled the product and let Quicken take the market. Microsoft then discontinued the international versions in the wake of Mint.com and other Yodlee-based web applications. Mint.com appears to be the most successful of the bunch and was bought by Quicken to replace their terrible Quicken Online.

Microsoft Money was fantastic because it:

  • Supported multiple currencies properly (I need GBP, USD and JPY with the ability to transfer between accounts)
  • Had seperate business accounts and expense tracking
  • Amazing reporting features
  • The invaluable cashflow graph which I still have not found in any competing product, web or client based

The last version was released in 2008 and this was the first version to contain product activation. Thanks to the product’s cancellation, Microsoft has quietly released a “Sunset” edition of Microsoft Money – a full copy of Microsoft Money Plus without the product activation entirely for free so users won’t have to worry about installing Money after the activation servers have gone down. The bank synchronisation is not included but this was only supported for US bank accounts anyway.

With the fantastic Dropbox, you can sync your Money data file between all the computers you use (even Mac OSX running Money under Parallels). The Money data file is very small (6 years of transactions here total 10MB).

The combination of MS Money and Dropbox gives you the best of both worlds:

  • Cloud storage and backup
  • Nobody snooping on your data, datamining your purchase habits (see Mint, Wesabe etc)
  • Instant UI response times because Money is a local app
  • Access your data from multiple locations – just install the free Money edition and Dropbox

Need mobile access? Just add LogMeIn to your iPad or iPhone.


Lexmark adds Twitter to an All in One printer … why?

Just noticed on The Register that Lexmark have added Twitter to a new range of All In One printers. See

They have actually written a client for the tiny little touchscreen display on the scanner. Are people really that addicted that they need to use Twitter while waiting for something to copy or scan? Why not use their phone? Because this way it looks like you are “fiddling with the settings”?

This is almost as pointless as the stupid talking printer driver you have to install on Windows when using Lexmark printers. “PRINTING STARTED.” “PRINTING COMPLETE.”


New cleaner site design

I’ve updated my site’s design again, this time using the base WordPress theme template from Hybrid. The old theme I was using was far too busy, so I wanted something cleaner.

This is the now the second time I’ve done some web development on OSX. I am using Coda as an IDE. I was pleasantly surprised to find PHP built into OSX, remembering how tiresome it was to get PHP ready on Windows (let alone getting it running in IIS7).

Still working on fixing for IE6 – halfway there. The transparency effects are turned off with some CSS hacking but there are still bugs.


Skype changes its mind – drops 3G call charges

That was quick: iPhone update: now supports multitasking, no additional charges for calling over 3G

Skype has dropped their plans to charge for 3G calls and have released an update to their iPhone client that finally supports multitasking.

At Skype, we believe that better call quality and better availability (which is achieved with an app capable of multitasking and/or making calls over 3G) lead to increased call frequency and longer calls. We also believe that the mobile world is in a period of significant change, for example, with some operators starting to move to tiered pricing models.

In light of that, we no longer have plans to charge a supplement to make calls over 3G. We’re delighted to make it easier for you to talk for even longer and do even more together using Skype.

Notice that they do not mention Video Calling – they will almost certainly charge for this in the future based on the survey in my previous post.


Skype trying to charge for Mobile

I got an interesting invitation to fill in a survey about Skype Mobile. Skype on iPhone is an application that is deliberately ignored by Skype while they try and figure out how to make money from it. Their recent spat with Fring, who have implemented 3G Skype, background multitasking and video chat on iPhone 4 already, highlights their position on this. There is now no way to use Skype on Android after Fring had to remove the service since Skype refuse to release a client. They pulled the perfectly functional Windows Mobile version stating the quality wasn’t good enough.

The survey asks about what price plans would be acceptable to use Skype on mobile, enabling features such as 3G and Video chat. Would I pay 5.70GBP to use Skype even with the sweetener of 5.70GBP Skype credit (that expires in a month)? No way. I pay for my unlimited 3G data plan already.


Updated: Japan iPad 3G is NOT “not exactly” SIM-locked – Jobs says so

There is a massive hullabaloo about Softbank’s exclusive deal with Apple for the 3G iPads here. Currently, you cannot get a 3G iPad without going through Softbank and signing up for a data plan (either 2 years or some terrible 4,000 yen per 1GB “offer”). This is in stark contrast to the fantastic deal Americans get in the US with AT&T.

Softbank appears to be announcing to the press that there will be a “SIM Lock” (SIMロック).

http://plusd.itmedia.co.jp/mobile/articles/1005/10/news030.html

ところが、5月8日にソフトバンクモバイルが公表したiPad販売に関する情報では、日本国内のソフトバンクショップやソフトバンクケータイ取扱店で販売されるiPadのWi-Fi+3G版は、ソフトバンクモバイルの3Gネットワークでしか使えないように、SIMロックがかかっているというアナウンスがあった。

“According to information released by Softbank on May 8, iPad wi-fi+3G models sold from Softbank shops will be SIM locked so that they can only connect to Softbank Mobile’s network.

I think they are lying. I don’t believe that the devices are SIM locked in any way. The only “lock” is that you must sign up to Softbank to get one, and they won’t sell you a microSIM for an international model.

Mobileinjapan.com reported a response from Steve Jobs stating that

Actually, the version of iPad sold in Japan does accept international SIMs.

I decided to email him myself and I got a reply:

image

An email reply from Jobs appears to be a rite of passage for bloggers now – I have replied asking for clarity but he doesn’t appear to get into conversations unless you are really interesting (which I’m not).

Based on the reply above, are we meant to believe that they have developed a new SIM-locking system that unlocks your device when you leave Japan? Of course they haven’t, that would be stupid. If the devices are SIM-locked, then international microSIMs simply would not work in them. Therefore, they are not SIM-locked.

What I believe Jobs is referring to by “locking” is that you can only buy a 3G iPad after “locking” yourself into Softbank. Docomo and E-mobile (both with networks that would support the iPad) are now unable to sell wireless plans. Not because of any technical reason, but because they cannot sell the iPads themselves, and all 3G iPad owners will be locked into 2 year contracts.

This is why I don’t think the iPads are SIM locked – simply because they don’t have to be. Normal Japanese phones have carrier specific settings built in (access points, MMS gateways etc) with no way of changing them so switching a SIM card would never work. Softbank must be very scared of the prospect of the market opening up like Europe.

Update: Well, he replied.

image

Not exactly SIM-locked? What does that mean? Maybe they HAVE developed a new SIM locking system that uses the GPS to determine the country you are in, or iTunes unlocks the device when you insert a non-Japan microSIM.

Another update: The Softbank Sucks blog appears to think that there is a software lock on Japanese iPads (possibly all iPads?) that is only active when the SIM Mobile Country Code is Japan’s. Meaning, if the SIM is a Japanese SIM, it must be a Softbank SIM. Absolutely appalling if true. The only way Docomo would be able to get around it is if they lied about the country code on their SIMs.


No native Japanese text in Windows Phone 7 … yet

The first preview version of the Windows Phone 7 SDK is out and it doesn’t support Japanese (or non-Latin) text in the English ROM. This is a huge disappointment.

image

One of the major advantages the iPhone has over almost every other smartphone platform (and the major reason I bought mine in the first place – I needed Japanese language support) is the built in support for non-Latin languages and their input methods. This allows Apple to provide one single worldwide firmware edition.

Previous versions of Windows Mobile have required users to hack in Japanese fonts using the registry and rely on some awful third party hacks to get Japanese IMEs working. I seriously hope that before WP7 is finished, Microsoft just install worldwide fonts and IMEs like they started to do with Vista. There is no excuse. We are unlikely to get low-level access to the registry this time around to hack the support in ourselves to non-Japanese ROMs.

One of their slides is supposed to imply that the Metro theme “Celebrates Typography”

image

— more like it totally ignores it. I suppose screens of square boxes fits the “Authentically Digital” principle.