{"id":4777,"date":"2021-08-06T04:23:24","date_gmt":"2021-08-06T04:23:24","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=4777"},"modified":"2021-08-06T04:51:43","modified_gmt":"2021-08-06T04:51:43","slug":"asynchronous-programming-using-async-await-in-c-sharp","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/","title":{"rendered":"Asynchronous programming using Async Await in C#"},"content":{"rendered":"<p>In this topic, I will discuss an important concept of C# which can make your application more responsive and fast with the help of asynchronous programming. <\/p>\n<h2>Summary:-<\/h2>\n<p>In C# We can perform asynchronous programming by using async and await keywords. Asynchronous coding is required where you need to multi-thread your code. You need to start another task thread that can run independently of your main task thread. In the async approach, we can just execute long-running tasks and continue with other tasks. <\/p>\n<p>These long-running tasks do the job in a different thread and when they complete it, they notify our main code, and our code can execute the next actions from here. Here we are referring to the main thread which deals with the UI or the thread that primarily processes a <a href=\"https:\/\/studysection.com\/blog\/latest-backend-tools-in-web-development\/\">web request<\/a>.<\/p>\n<h3>Benefits of Asynchronous programming.<\/h3>\n<ol>\n<li>It improves application performance.<\/li>\n<li>It increases application responsiveness.<\/li>\n<li>Enable parallel programming<\/li>\n<li>You can perform other tasks while your time-consuming task is executing independently.<\/li>\n<li>It prevents the blocking of other independent tasks.<\/li>\n<li>It makes the UI more responsive.<\/li>\n<li>Make your application asynchronous just with these two keywords async-await.<\/li>\n<\/ol>\n<p><strong>Let&#8217;s understand how we can achieve asynchronous programming using async-await with some code examples.<\/strong><\/p>\n<h3>Example 1:-<\/h3>\n<p>Let&#8217;s suppose we have software that manages the cooking process. We need to make breakfast which consists of tea and a sandwich. Let\u2019s try it with synchronous code.<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/class-code.png\" alt=\"Programming class-code\"\/><\/p>\n<h3>Output:-<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/class-code1.png\" alt=\"Programming class-code1\"\/><br \/>\n<em style=\"color:red;\">It has taken 15 seconds to make breakfast in the synchronous approach.<\/em><br \/>\n<strong>Now let see its result with an asynchronous approach using async-await.<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/class-code2.png\" alt=\"class-code2\" \/><\/p>\n<h3>Output:-<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/class-code3.png\" alt=\"class-code3\"\/><br \/>\n<em style=\"color:red;\">It has taken 10 seconds to make breakfast in an asynchronous approach.<\/em><\/p>\n<h3>Conclusion:-<\/h3>\n<p>In this example, we used the breakfast process to understand the importance of asynchronous programming. Our application needs to make tea and sandwiches. Let&#8217;s assume a sandwich takes 10 seconds to make and tea takes 5 seconds to make.<br \/>\nIn the synchronous approach, it will first prepare a sandwich and then tea. We are waiting here for a sandwich and blocking the tea-making process which is completely independent of the sandwich-making process. It will wait for 10 seconds and then it will start the tea-making process. Therefore it will take 15 seconds to make breakfast. Here we have wasted 5 seconds by waiting for a sandwich for 10 seconds.<br \/>\nBut in an asynchronous approach, we can run both tasks parallel to each other. Here we can make tea and sandwich at the same time, which will save us 5 seconds. Therefore it has taken only 10 seconds to make breakfast.<br \/>\nIn big application scenarios where we need to deal with large amounts of data and big computations, asynchronous programming can make it more efficient and responsive.<\/p>\n<p><small>Get certification for your knowledge in the fundamentals of Computer functioning by clearing the <a href=\"https:\/\/www.studysection.com\/computer-applications-diploma-advanced\">Computer Certification Exam<\/a> conducted by StudySection. After going through this Computer Certification exam, you will be able to evaluate your basic knowledge of computers. <\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this topic, I will discuss an important concept of C# which can make your application more responsive and fast<\/p>\n","protected":false},"author":1,"featured_media":4780,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[687,66],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Asynchronous programming using Async Await in C# - SS Blog<\/title>\n<meta name=\"description\" content=\"In this topic, I will discuss an important concept of C# which can make your application fast with the help of 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:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Asynchronous programming using Async Await in C# - SS Blog\" \/>\n<meta property=\"og:description\" content=\"In this topic, I will discuss an important concept of C# which can make your application fast with the help of asynchronous programming.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-06T04:23:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-06T04:51:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/Programming.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Asynchronous programming using Async Await in C#\",\"datePublished\":\"2021-08-06T04:23:24+00:00\",\"dateModified\":\"2021-08-06T04:51:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\"},\"wordCount\":483,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"Async\",\"programming\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\",\"url\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\",\"name\":\"Asynchronous programming using Async Await in C# - SS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-08-06T04:23:24+00:00\",\"dateModified\":\"2021-08-06T04:51:43+00:00\",\"description\":\"In this topic, I will discuss an important concept of C# which can make your application fast with the help of asynchronous programming.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Asynchronous programming using Async Await in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Asynchronous programming using Async Await in C# - SS Blog","description":"In this topic, I will discuss an important concept of C# which can make your application fast with the help of 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:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/","og_locale":"en_US","og_type":"article","og_title":"Asynchronous programming using Async Await in C# - SS Blog","og_description":"In this topic, I will discuss an important concept of C# which can make your application fast with the help of asynchronous programming.","og_url":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-08-06T04:23:24+00:00","article_modified_time":"2021-08-06T04:51:43+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/Programming.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Asynchronous programming using Async Await in C#","datePublished":"2021-08-06T04:23:24+00:00","dateModified":"2021-08-06T04:51:43+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/"},"wordCount":483,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["Async","programming"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/","url":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/","name":"Asynchronous programming using Async Await in C# - SS Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-08-06T04:23:24+00:00","dateModified":"2021-08-06T04:51:43+00:00","description":"In this topic, I will discuss an important concept of C# which can make your application fast with the help of asynchronous programming.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/asynchronous-programming-using-async-await-in-c-sharp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Asynchronous programming using Async Await in C#"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":390,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4777"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=4777"}],"version-history":[{"count":5,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4777\/revisions"}],"predecessor-version":[{"id":4787,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4777\/revisions\/4787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/4780"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=4777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=4777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=4777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}