{"id":760,"date":"2023-03-06T14:35:04","date_gmt":"2023-03-06T07:35:04","guid":{"rendered":"https:\/\/csharptutorial.net\/?page_id=760"},"modified":"2023-03-22T10:46:26","modified_gmt":"2023-03-22T03:46:26","slug":"csharp-concurrency","status":"publish","type":"page","link":"https:\/\/www.csharptutorial.net\/csharp-concurrency\/","title":{"rendered":"C# Concurrency"},"content":{"rendered":"\n<p>This C# concurrency series helps you master multithreading and asynchronous programming in C# and shows you how to use C# concurrency to improve the application&#8217;s performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What you&#8217;ll learn<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand the basic concepts including threads, processes, and the difference between threads and processes.<\/li>\n\n\n\n<li>Fully Utilize the power of the task parallel library (TPL) using Task objects.<\/li>\n\n\n\n<li>Deeply understand how async\/await works in C#.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 1. Multithreading<\/h2>\n\n\n\n<p>This section helps you understand the basic concepts of thread and multithreading in C# and build a strong foundation for developing asynchronous applications.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/csharptutorial.net\/c-concurrency\/csharp-thread\/\">Thread<\/a> &#8211; understand the Thread object and how to create a multithreading application in C#.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-background-thread\/\">Background thread<\/a> &#8211; understand background threads and the differences between background &amp; foreground threads.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-threadpool\/\">ThreadPool<\/a> &#8211; learn how to use the thread pool to manage threads more efficiently.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 2. Task-based Asynchronous Programming (TAP)<\/h2>\n\n\n\n<p>The task-based asynchronous programming (TAP) is the modern programming model in C# that simplifies the process of writing asynchronous code.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-task\/\">Task<\/a> &#8211; explain the task-based asynchronous programming model and show you how to use the <code>Task<\/code> class to create asynchronous operations that can be executed concurrently.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-continuewith\/\">Chain multiple tasks<\/a> &#8211; show you how to use the <code>ContinueWith()<\/code> method of the <code>Task<\/code> class to chain multiple tasks.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-task-handle-exception\/\">Handle exceptions<\/a> &#8211; learn how to handle <code>AggregateException<\/code> exceptions that are thrown by asynchronous operations executed by tasks.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-async-await\/\">Async\/Await<\/a> &#8211; show you how to use the <code>async\/await<\/code> keywords to create methods that execute asynchronously.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-cancellationtokensource\/\">Canceling an asynchronous operation<\/a> &#8211; learn how to cancel an asynchronous operation using the cancellation token.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-whenany\/\">Task.WhenAny()<\/a> &#8211; wait for the first task in a collection of tasks to complete and process the result of that task.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-whenall\/\">Task.WhenAll()<\/a> &#8211; wait for all tasks in a collection of tasks to complete.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 3. Thread Synchronization<\/h2>\n\n\n\n<p>This section shows you how to coordinate the execution of multiple threads to ensure that they access the shared resources in a thread-safe manner and prevent race conditions as well as other synchronization issues.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-lock\/\">lock statement<\/a> &#8211; show you how to use the lock statement to prevent the risk of race conditions and synchronization when multiple tasks (or threads) attempt to access the same shared resources.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-deadlock\/\">Deadlock<\/a> &#8211; understand what is a deadlock, how it occurs, and how to fix it using various techniques.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/c-interlocked\/\">Interlocked<\/a> &#8211; learn how to perform atomic operations on a shared variable using methods of the Interlocked class. <\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-readerwriterlockslim\/\">ReaderWriterLockSlim<\/a> &#8211; guide you on how to use the <code>ReaderWriterLockSlim<\/code> class to allow multiple threads to read from a shared resource simultaneously while preventing other threads from concurrent writes.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-semaphoreslim\/\">SemaphoreSlim<\/a> &#8211; learn how to use the semaphore object to limit the number of threads that access shared resources concurrently.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 4. Thread Signaling<\/h2>\n\n\n\n<p>This section shows you how to communicate between threads via signals using signaling objects including AutoResetEvent, ManualResetEventSlim, and CountDownEvent.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-autoresetevent\/\">AutoResetEvent<\/a> &#8211; learn how to send signals between threads using the <code>AutoResetEvent<\/code> object.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-manualreseteventslim\/\">ManualResetEvent<\/a> &#8211; show you how to use the <code>ManualResetEventSlim<\/code> class to signal events between threads.<\/li>\n\n\n\n<li><a href=\"https:\/\/csharptutorial.net\/csharp-concurrency\/csharp-countdownevent\/\">CountdownEvent<\/a> &#8211; guide you on how to use the <code>CountdownEvent<\/code> object to wait for a specified number of events before continuing execution on waiting threads.<\/li>\n<\/ul>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This C# concurrency series helps you master the multithreading and asynchronous programming in C#.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-760","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/comments?post=760"}],"version-history":[{"count":5,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/760\/revisions"}],"predecessor-version":[{"id":1175,"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/pages\/760\/revisions\/1175"}],"wp:attachment":[{"href":"https:\/\/www.csharptutorial.net\/wp-json\/wp\/v2\/media?parent=760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}