{"id":6672,"date":"2013-07-24T17:13:41","date_gmt":"2013-07-25T00:13:41","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=6672"},"modified":"2013-07-24T17:13:41","modified_gmt":"2013-07-25T00:13:41","slug":"major-upgrades-to-xamarins-platform-async-is-here","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/major-upgrades-to-xamarins-platform-async-is-here\/","title":{"rendered":"Major Upgrades to Xamarin\u2019s Platform: Async is Here"},"content":{"rendered":"<p>\t\t\t\tToday we are happy to introduce a major upgrade to the Xamarin platform. We are bringing C# 5.0 with async to all of our supported platforms. Async greatly simplifies the creation of responsive user experiences, which are particularly important for mobile applications.<\/p>\n<p>We use apps to make the spare moments in life productive, and to help us better navigate the world with real-time, contextual information. Fast, fluid, instant-gratification apps are a must for mobile applications and C# async gives developers the tools to make this happen.<\/p>\n<p>Until today, the only option for you to build responsive apps that work around network delays, connectivity issues, and complex data queries and processing is to use traditional asynchronous programming techniques. While leveraging common asynchronous patterns would lead to a better app for your users, they are not easy on the developer. You can quickly end up in a situation where your code has a cascade of nested callbacks that make it difficult to debug problems and create more opportunities for error. Even worse, sometimes the complexity is such that developers tend to cut corners on some code paths, leading to suboptimal experiences when applications are used in the wild.<\/p>\n<p>The async and await keywords in C# 5.0 now available to Xamarin developers make asynchronous programming incredibly pleasant. You end up with code that is much more linear and much easier to understand. The compiler does a lot of magic for you which simplifies your code and your life. The following comparison demonstrates the impact of using C# async in your apps. The first version is implemented without async:<\/p>\n<pre class=\"lang:csharp decode:true\">\nprivate void SnapAndPost ()\n{\n\tBusy = true;\n\n\tUpdateUIStatus (&quot;Taking a picture&quot;);\n\n\tvar picker = new Xamarin.Media.MediaPicker ();\n\tvar picTask = picker.TakePhotoAsync (new Xamarin.Media.StoreCameraMediaOptions ());\n\n\tpicTask.ContinueWith ((picRetTask) =&gt; {\n\t\tInvokeOnMainThread (() =&gt; {\n\t\t\tif (picRetTask.IsCanceled) {\n\t\t\t\tBusy = false;\n\t\t\t\tUpdateUIStatus (&quot;Canceled&quot;);\n\t\t\t} else {\n\t\t\t\tvar tagsCtrl = new GetTagsUIViewController (picRetTask.Result.GetStream ());\n\t\t\t\tPresentViewController (tagsCtrl, true, () =&gt; {\n\t\t\t\t\tUpdateUIStatus (&quot;Submitting picture to server&quot;);\n\n\t\t\t\t\tvar uploadTask = new Task (() =&gt; {\n\t\t\t\t\t\treturn PostPicToService (picRetTask.Result.GetStream (), tagsCtrl.Tags);\n\t\t\t\t\t});\n\n\t\t\t\t\tuploadTask.ContinueWith ((uploadRetTask) =&gt; {\n\t\t\t\t\t\tInvokeOnMainThread (() =&gt; {\n\t\t\t\t\t\t\tBusy = false;\n\t\t\t\t\t\t\tUpdateUIStatus (uploadRetTask.Result.Failed ? &quot;Canceled&quot; : &quot;Success&quot;);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tuploadTask.Start ();\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t});\n}\n<\/pre>\n<p>And this version was implemented with the benefit of async:<\/p>\n<pre class=\"lang:csharp decode:true\">\nprivate async Task SnapAndPostAsync ()\n{\n\ttry {\n\t\tBusy = true;\n\n\t\tUpdateUIStatus (&quot;Taking a picture&quot;);\n\n\t\tvar picker = new Xamarin.Media.MediaPicker ();\n\t\tvar mFile = await picker.TakePhotoAsync (new Xamarin.Media.StoreCameraMediaOptions ());\n\n\t\tvar tagsCtrl = new GetTagsUIViewController (mFile.GetStream ());\n\n\t\t\/\/ Call new iOS await API\n\t\tawait PresentViewControllerAsync (tagsCtrl, true);\n\n\t\tUpdateUIStatus (&quot;Submitting picture to server&quot;);\n\n\t\tawait PostPicToServiceAsync (mFile.GetStream (), tagsCtrl.Tags);\n\n\t\tUpdateUIStatus (&quot;Success&quot;);\n\t} catch (OperationCanceledException) {\n\t\tUpdateUIStatus (&quot;Canceled&quot;);\n\t} finally {\n\t\tBusy = false;\n\t}\n}\n<\/pre>\n<p>With this release, we\u2019ve gone beyond just adding async support to our base class libraries. We\u2019ve actually asyncified native iOS and Android APIs, making it possible to take advantage of async in the platform-specific areas of your apps\u2014something no other programming language can do, and further cementing C# as the <a href=\"\/eight-reasons-c-sharp-is-the-best-language-for-mobile-development\/\">best language for mobile development<\/a>.<\/p>\n<p>In addition to C# 5.0 async, this Xamarin update also upgrades Xamarin\u2019s Mono to 3.0 for Xamarin.Android, Xamarin.Mac and Xamarin.iOS. Developers will benefit from over 7000 individual commits made to Mono during the past two years. These improvements include new .Net 4.5 APIs, async-friendly System.Net.Http, better debugging support, a faster version of our garbage collector and we eliminated the frustration of dealing with generics on iOS devices. We\u2019ve also made it much faster for you to build and deploy Xamarin.iOS apps to devices for testing (up to seven times faster!), and we\u2019ve made it easier to create bindings of Android native jar files. See the release notes for <a href=\"http:\/\/docs.xamarin.com\/releases\/ios\/xamarin.ios_6\/xamarin.ios_6.4\">Xamarin.iOS<\/a> and <a href=\"http:\/\/docs.xamarin.com\/releases\/android\/xamarin.android_4\/xamarin.android_4.8\">Xamarin.Android<\/a> for all of the details.<\/p>\n<p>I\u2019ll be hosting a live webinar on August 15th to talk about how and why you should be using async in your mobile apps. Please join me!<\/p>\n<div class=\"centered\"><a class=\"action-button featured more\" href=\"http:\/\/resources.xamarin.com\/async_on_ios_and_android.html\">Register for Webinar<\/a><\/div>\n<hr \/>\n<p><i>Current subscribers can fire up Xamarin Studio or Visual Studio to update the latest version. \u00a0If you\u2019re not a current subscriber, visit <a href=\"http:\/\/store.xamarin.com\">store.xamarin.com<\/a> or <a href=\"http:\/\/xamarin.com\/download\">download our free Starter Edition.<\/a><\/i>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we are happy to introduce a major upgrade to the Xamarin platform. We are bringing C# 5.0 with async to all of our supported platforms. Async greatly simplifies the creation of responsive user experiences, which are particularly important for mobile applications. We use apps to make the spare moments in life productive, and to [&hellip;]<\/p>\n","protected":false},"author":1917,"featured_media":39167,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4],"class_list":["post-6672","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>Today we are happy to introduce a major upgrade to the Xamarin platform. We are bringing C# 5.0 with async to all of our supported platforms. Async greatly simplifies the creation of responsive user experiences, which are particularly important for mobile applications. We use apps to make the spare moments in life productive, and to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/6672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/1917"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=6672"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/6672\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=6672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=6672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=6672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}