{"id":1032,"date":"2019-12-03T19:15:00","date_gmt":"2019-12-03T18:15:00","guid":{"rendered":"http:\/\/cmagazine.test\/net-async-await-and-its-catches\/"},"modified":"2019-12-03T19:15:54","modified_gmt":"2019-12-03T18:15:54","slug":"net-async-await-and-its-catches","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/","title":{"rendered":".NET Async\/Await and its catches"},"content":{"rendered":"<p>Since the introduction of the <b>Task-based Asynchronous Pattern<\/b> (or TAP) with .NET 4.0 programmers have enjoyed a simpler and streamlined approach to <strong>asynchronous programming in .NET<\/strong>, improving performance and readability of their code.<\/p>\n<p>If you are already familiar with .NET TAP basic concepts, don\u2019t miss the opportunity to learn more from an expert: <b>Brandon Minnick<\/b>, developer advocate with <strong>Microsoft<\/strong>, will address some in his talk \u201c<em>Correcting Common Async\/Await Mistakes in .NET<\/em>\u201d at <b><a href=\"https:\/\/events.codemotion.com\/conferences\/milan\/2019\/\">Codemotion Milan 2019<\/a><\/b> &#8211; check the <a href=\"https:\/\/events.codemotion.com\/conferences\/milan\/2019\/agenda\/\">agenda<\/a>. Hurry up as <a href=\"https:\/\/www.eventbrite.co.uk\/e\/codemotion-milan-2019-conference-october-24-25-tickets-53998269277\">tickets are still available<\/a>!<\/p>\n<h2>Was it worth the Await?<\/h2>\n<p>Before TAP, .NET programmers had several alternatives to write non-blocking code:<\/p>\n<ul>\n<li>Using the <b>Asynchronous Programming Model<\/b> (APM), with its <code>Begin*<\/code>, <code>End*<\/code> methods and its <code>IAsyncResult<\/code> interface;<\/li>\n<li>The <b>Event-based Asynchronous Pattern<\/b> (EAP), which is the legacy event-based model introduce with .NET 2.0;<\/li>\n<li>Writing code at a lower level using <b>Threads<\/b> and the related synchronization primitives (<code>Mutex<\/code>, <code>Semaphore<\/code>, etc).<\/li>\n<\/ul>\n<p>All of these alternatives are somewhat cumbersome and difficult to handle compared to the Async\/Await paradigm introduced with TAP. They all require a lot of boilerplate just to get things up and running, with the obvious consequence of hurting readability and maintainability.<\/p>\n<p>TAP is instead very simple to grasp, as far as parallel programming can go. It is modelled around the concept of Tasks as the name implies. A Task is simply a generic asynchronous operation, some piece of code we want to run without blocking the caller or other tasks.<\/p>\n<h2>An async Hello World<\/h2>\n<p>So let\u2019s get started with a simple \u201c<b>hello world<\/b>\u201d example with the Async\/Await constructs. The goal of this simple program is to perform a few <i>HTTP GET<\/i> requests against a list of servers. A simple synchronous version would be:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/mbdv5gar\"><\/script><\/p>\n<p>The method <code><b>getDataSync()<\/b><\/code> performs an HTTP request using the <code>HttpClient<\/code> class in <code>System.Net.Http<\/code> and returns the result as a <code>String<\/code>. The method <code><b>DoWork()<\/b><\/code> calls the method <code><b>getDataSync()<\/b><\/code> for all the websites in the list.<\/p>\n<p>There is an obvious problem with this implementation: throughput. Requests are performed one after the other in sequence. This hurts the overall performance since our program is blocked waiting for a request to complete before attempting to perform anything else. Moreover, if an error occurs while performing one of the GET calls, the entire sequence is interrupted. This is often an undesired behaviour, as in case of errors we want to be able to gracefully rollback or continue with the other calls.<\/p>\n<p>Lastly, the main thread is also blocked for the entire time, making the program completely unresponsive. If this piece of code would be part of a desktop application, the GUI would freeze until all the requests are finally completed.<\/p>\n<p>So let\u2019s change the code to perform all the requests asynchronously and in a parallel fashion. To turn a normal method to an asynchronous one we must perform these changes:<\/p>\n<ul>\n<li>Add the <code><b>async<\/b><\/code> keyword to its definition. This enables the usage of the <code>await<\/code> operator inside that method. The <code><b>await<\/b><\/code> operator will suspend the execution of the <code>async<\/code> method until the asynchronous operation represented by its operand is completed;<\/li>\n<li>Change the return type to <code><b>Task&lt;T&gt;<\/b><\/code> where <code>T<\/code> is the return data type;<\/li>\n<li>Respect the naming convention: an asynchronous method name should end with the word \u201c<i>Async<\/i>\u201d;<\/li>\n<\/ul>\n<p>Here is how the <code>getDataAsync()<\/code> method looks like:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/Gz38mLKW\"><\/script><\/p>\n<p>While this will execute the requests in different Tasks, they will still be in a sequence, because of the await in the <code>foreach<\/code> loop. A better approach would be to let the Tasks run in parallel and let the <code>DoWork()<\/code> method return when they have all completed their mission. This can be easily achieved with the <code><b>Task.WaitAll()<\/b><\/code> method. To do so, we create an array of Tasks, populate it with the Tasks returned by each call of the <code>getDataSync()<\/code> method and then pass the array to <code>Task.WaitAll()<\/code> to wait for them:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/KeMFfKJ3\"><\/script><\/p>\n<h2>But there\u2019s a catch<\/h2>\n<p>Or there is not. So far we assumed things are always going smoothly. But what happens if an exception is thrown inside one of the async methods? Let\u2019s simulate this condition by adding a non existing URL to the list of sites to request. This will obviously make the <code>HttpClient<\/code> throw an <code>HttpRequestException<\/code> since the DNS request will fail.<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/E274Ham0\"><\/script><\/p>\n<p>As expected, an exception is thrown. The interesting fact here is that the exception is thrown by the <code>Task.WaitAll()<\/code> method, and it is a <code>System.AggregateException<\/code>. That is because the .NET framework will automatically surround our aysnc methods with try\/catch blocks to let the Task awaiter handle them. The exception thrown by the <code>HttpClient<\/code>, a <code>SocketException<\/code> in this case, can be accessed as an <code>InnerException<\/code>. Let\u2019s handle these exceptions in the <code>DoWorkAsync()<\/code> method:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/s9iQ8Wpx\"><\/script><\/p>\n<p>What if we want to manage the exception in the <code>getDataAsync()<\/code> method instead? As for any other method, we can simply wrap the await call inside a try\/catch block:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/6iJ79A8r\"><\/script><\/p>\n<p>This works as expected because <code>HttpClient.GetStringAsync()<\/code> method will assign any exception that occurs during its execution to the returning Task.<\/p>\n<h2>Conclusions<\/h2>\n<p>There is a lot more to cover about asynchronous programming with .NET, considering best practices, optimization and exception handling. There are several odd cases in which exception handling may give you some headaches when dealing with async methods.<\/p>\n<p>Again, if you want to learn more about it, don\u2019t miss the talk <b>Brandon Minnick<\/b>, developer advocate with <strong>Microsoft<\/strong>, will give at <b><a href=\"https:\/\/events.codemotion.com\/conferences\/milan\/2019\/\">Codemotion Milan 2019<\/a><\/b> where he will address more advanced topics and show some interesting examples. <a href=\"https:\/\/www.eventbrite.co.uk\/e\/codemotion-milan-2019-conference-october-24-25-tickets-53998269277\">Get your ticket here<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.<\/p>\n","protected":false},"author":31,"featured_media":1045,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[36],"tags":[22,62],"collections":[],"class_list":{"0":"post-1032","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-backend","8":"tag-codemotion-milan","9":"tag-dot-net","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>.NET Async\/Await and its catches - Codemotion Magazine<\/title>\n<meta name=\"description\" content=\"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\".NET Async\/Await and its catches\" \/>\n<meta property=\"og:description\" content=\"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-03T18:15:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-03T18:15:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1013\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sergio Monteleone\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sergio Monteleone\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\"},\"author\":{\"name\":\"Sergio Monteleone\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/1175f6a51ed61a57ce2bbe8f28682052\"},\"headline\":\".NET Async\/Await and its catches\",\"datePublished\":\"2019-12-03T18:15:00+00:00\",\"dateModified\":\"2019-12-03T18:15:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\"},\"wordCount\":877,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg\",\"keywords\":[\"Codemotion Milan\",\"Dot NET\"],\"articleSection\":[\"Backend\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\",\"name\":\".NET Async\/Await and its catches - Codemotion Magazine\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg\",\"datePublished\":\"2019-12-03T18:15:00+00:00\",\"dateModified\":\"2019-12-03T18:15:54+00:00\",\"description\":\"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg\",\"width\":1013,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Backend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\".NET Async\/Await and its catches\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/1175f6a51ed61a57ce2bbe8f28682052\",\"name\":\"Sergio Monteleone\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/01ed53edef772160c6afbbad5e36940f0cd612cbcf1a6dc3178588bd2b44708c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/01ed53edef772160c6afbbad5e36940f0cd612cbcf1a6dc3178588bd2b44708c?s=96&d=mm&r=g\",\"caption\":\"Sergio Monteleone\"},\"description\":\"Software developer and the co-founder of Moga Software s.r.l., a software house based in Italy. I tend to write code for anything that has a C\/C++ compiler, but don't mind using other technologies and languages. I love cats, dogs and, more in general, any lifeform when Lifeform.numLegs() &lt;= 4.\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/sergio-monteleone\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":".NET Async\/Await and its catches - Codemotion Magazine","description":"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/","og_locale":"en_US","og_type":"article","og_title":".NET Async\/Await and its catches","og_description":"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.","og_url":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2019-12-03T18:15:00+00:00","article_modified_time":"2019-12-03T18:15:54+00:00","og_image":[{"width":1013,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg","type":"image\/jpeg"}],"author":"Sergio Monteleone","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Sergio Monteleone","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/"},"author":{"name":"Sergio Monteleone","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/1175f6a51ed61a57ce2bbe8f28682052"},"headline":".NET Async\/Await and its catches","datePublished":"2019-12-03T18:15:00+00:00","dateModified":"2019-12-03T18:15:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/"},"wordCount":877,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg","keywords":["Codemotion Milan","Dot NET"],"articleSection":["Backend"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/","url":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/","name":".NET Async\/Await and its catches - Codemotion Magazine","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg","datePublished":"2019-12-03T18:15:00+00:00","dateModified":"2019-12-03T18:15:54+00:00","description":"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg","width":1013,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/net-async-await-and-its-catches\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Backend","item":"https:\/\/www.codemotion.com\/magazine\/backend\/"},{"@type":"ListItem","position":3,"name":".NET Async\/Await and its catches"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/1175f6a51ed61a57ce2bbe8f28682052","name":"Sergio Monteleone","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/01ed53edef772160c6afbbad5e36940f0cd612cbcf1a6dc3178588bd2b44708c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/01ed53edef772160c6afbbad5e36940f0cd612cbcf1a6dc3178588bd2b44708c?s=96&d=mm&r=g","caption":"Sergio Monteleone"},"description":"Software developer and the co-founder of Moga Software s.r.l., a software house based in Italy. I tend to write code for anything that has a C\/C++ compiler, but don't mind using other technologies and languages. I love cats, dogs and, more in general, any lifeform when Lifeform.numLegs() &lt;= 4.","url":"https:\/\/www.codemotion.com\/magazine\/author\/sergio-monteleone\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-600x600.jpg","author_info":{"display_name":"Sergio Monteleone","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/sergio-monteleone\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg",1013,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-768x512.jpg",768,512,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg",1013,675,false],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg",1013,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg",1013,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1.jpg",100,67,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/Stefano-Snaidero-20171110_0021__B9A9864-1-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Sergio Monteleone","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/sergio-monteleone\/"},"uagb_comment_info":0,"uagb_excerpt":"Introduction to .NET Task-based Asynchronous Pattern (or TAP), and how this new approach make simpler, more readable and effective asynchronous programming.","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/1032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=1032"}],"version-history":[{"count":2,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/1032\/revisions"}],"predecessor-version":[{"id":1940,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/1032\/revisions\/1940"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/1045"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=1032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=1032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=1032"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=1032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}