{"id":6027,"date":"2022-08-30T04:43:44","date_gmt":"2022-08-30T04:43:44","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=6027"},"modified":"2022-08-30T04:43:44","modified_gmt":"2022-08-30T04:43:44","slug":"asynchronous-programming","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/asynchronous-programming\/","title":{"rendered":"Asynchronous Programming"},"content":{"rendered":"<p>Asynchronous programming is an effective solution for blocked or delayed access to resources. Suppose an activity in a synchronous process is blocked in a way, that the entire program must wait, which increases processing time.<\/p>\n<p>It should be used if your demands are I\/O-bound (for example, reading and writing to a file system, accessing a database, or requesting data via a network). Another case that is advantageous for developing async code is when you have CPU-bound code, such as when you are conducting an expensive calculation.<\/p>\n<p>Async programming in C# uses the async and await keywords. You can use them to work with .NET Framework and.NET Core resources, among other things. Async methods are asynchronous methods specified with the async keyword.<\/p>\n<h2>Async<\/h2>\n<p>This keyword designates a function as being asynchronous. To put it another way, we can invoke a function asynchronously if we prefix it with the async keyword.<br \/>\n<code>public async void CallAnyfunction() { }<\/code><\/p>\n<h3>Await<\/h3>\n<p>We do use this keyword when calling any function asynchronously.<br \/>\nSuppose we have a long-running process.<br \/>\n<code>static void Main()<br \/>\n    {<br \/>\n        var count = await  Method1(); \/\/used await keyword<br \/>\n        Method2(count); \/\/dependent on method1<br \/>\n    }<br \/>\npublic static async Task&lt;int> Method1()<br \/>\n    {<br \/>\n        int count = 0;<br \/>\n        await Task.Run(() =><br \/>\n        {<br \/>\n            for (int i = 0; i &lt; 100; i++)<br \/>\n            {<br \/>\n                Console.WriteLine(\" Method 1\");<br \/>\n                count += 1;<br \/>\n            }<br \/>\n        });<br \/>\n        return count;<br \/>\n    }<br \/>\n  public static void Method2(int count)<br \/>\n    {<br \/>\n      Console.WriteLine(\"Total count is \" + count);<br \/>\n    }<\/code><\/p>\n<h3>Advantages of using this approach:<\/h3>\n<ul>\n<li>Maintain UI responsiveness <\/li>\n<li>Possibility of improving performance by parallel processing<\/li>\n<li>Avoid running out of the thread pool by &#8220;stopping&#8221; execution during asynchronous activity and freeing threads into the thread pool. <\/li>\n<li>Performance Improvement<\/li>\n<\/ul>\n<p><small><em>If you have skills in PHP programming and you want to enhance your career in this field, a PHP certification from StudySection can help you reach your desired goals. Both beginner level and expert level <a href=\"https:\/\/www.studysection.com\/php-web-developer-foundation-diploma\">PHP Certification Exams<\/a> are offered by StudySection along with other programming certification exams. <\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Asynchronous programming is an effective solution for blocked or delayed access to resources. Suppose an activity in a synchronous process<\/p>\n","protected":false},"author":1,"featured_media":6028,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Asynchronous programming - StudySection Blog<\/title>\n<meta name=\"description\" content=\"Asynchronous programming is an effective solution for blocked or delayed access to resources.\" \/>\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\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Asynchronous programming - StudySection Blog\" \/>\n<meta property=\"og:description\" content=\"Asynchronous programming is an effective solution for blocked or delayed access to resources.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/asynchronous-programming\/\" \/>\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=\"2022-08-30T04:43:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/08\/Asynchronous-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<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Asynchronous Programming\",\"datePublished\":\"2022-08-30T04:43:44+00:00\",\"dateModified\":\"2022-08-30T04:43:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/\"},\"wordCount\":255,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/asynchronous-programming\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/\",\"url\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/\",\"name\":\"Asynchronous programming - StudySection Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2022-08-30T04:43:44+00:00\",\"dateModified\":\"2022-08-30T04:43:44+00:00\",\"description\":\"Asynchronous programming is an effective solution for blocked or delayed access to resources.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/asynchronous-programming\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/asynchronous-programming\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Asynchronous Programming\"}]},{\"@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 - StudySection Blog","description":"Asynchronous programming is an effective solution for blocked or delayed access to resources.","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\/","og_locale":"en_US","og_type":"article","og_title":"Asynchronous programming - StudySection Blog","og_description":"Asynchronous programming is an effective solution for blocked or delayed access to resources.","og_url":"https:\/\/studysection.com\/blog\/asynchronous-programming\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2022-08-30T04:43:44+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/08\/Asynchronous-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"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/asynchronous-programming\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/asynchronous-programming\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Asynchronous Programming","datePublished":"2022-08-30T04:43:44+00:00","dateModified":"2022-08-30T04:43:44+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/asynchronous-programming\/"},"wordCount":255,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/asynchronous-programming\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/asynchronous-programming\/","url":"https:\/\/studysection.com\/blog\/asynchronous-programming\/","name":"Asynchronous programming - StudySection Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2022-08-30T04:43:44+00:00","dateModified":"2022-08-30T04:43:44+00:00","description":"Asynchronous programming is an effective solution for blocked or delayed access to resources.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/asynchronous-programming\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/asynchronous-programming\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/asynchronous-programming\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Asynchronous Programming"}]},{"@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":179,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/6027"}],"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=6027"}],"version-history":[{"count":1,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/6027\/revisions"}],"predecessor-version":[{"id":6029,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/6027\/revisions\/6029"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/6028"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=6027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=6027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=6027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}