March 11, 2013

Xamarin previews C# async on iOS and Android

By

One of the most requested features we’re hearing at Xamarin these days is support for async in C#.  Today, we are very happy to announce the first preview of async support in our products. The code is available now on the Alpha channel in the Xamarin Updater.

First-class support for asynchronicity is a powerful and brilliantly simple language tool.

  • It makes it easy to write responsive user interfaces, which in turn makes for delighted users
  • It makes complex workflows, with their error handling, natural to write.  This translates into proper error messages and proper program recovery; and finally
  • By letting the compiler do the work for you, it eliminates bugs from your code, and enables you to enjoy your work and to focus on what really matters for your application.

This is best seen by watching it in action.  See how this piece of old C# code turns into a piece of beauty.  Error handling and dealing with the UI thread go from painful to trivial. To learn more about how to use async start from this article.

While asynchronicity is the main theme of this release, we also pack two years of improvements to the Mono runtime spread over more than 7,000 individual commits that are now available to Android, Mac and iOS users.

Among the new features:

  • New .NET 4.5 APIs
  • iOS generic compiler improvements, fewer “Attempting to JIT compile method” errors.
  • Async-friendly System.Net.Http
  • Improved debugging stack
  • Variant and contravariant interfaces

New .NET 4.5 APIs: We’re bringing in a huge refresh to the class libraries. Our current products have historically been an extension of the Silverlight API. Now our class libraries are based on the .NET 4.5 profile.

iOS Batch Compiler Improvements: On iOS we now generate “shareable code” for value types, a truly revolutionary innovation in code generation technology. In practical terms this means that a whole range of code that previously crashed with a “Attempting to JIT compile method” now works. While we still provide the high-performance, and fine-tuned generic code that we can infer –for example direct calls to a method Foo<T>(T x)– we generate a value-type shared version of Foo<T>(T x) that can be used in dynamic cases that previously failed. What was once a dream, is now a reality.

New System.Net.Http: This is such a delightful async API that it deserves to be called out on its own. This is an async-friendly HTTP stack, and makes building clients apps trivial We now ship System.Net.Http, a new, async ready, HTTP stack that have been designed from the bottom up to work well with the new version of the language.

Debugging Upgrades: Our debugger has received a lots of small improvements and fixes, they add up and you will notice how all the small details now work more smoothly than before.

Variance and Contravariance: With the upgrade to our class libraries, we have introduced support for variance and contravariance in the core types. While this change enables a whole class of new code to be written, it also means that some old code that was not covariant/contravariance friendly will have to be adjusted.

Please use the forums to tell us all about your experiences with async and the other goodies in this release.

TwitterFacebookGoogle+LinkedInEmail