Share E-Book
Scan to open this page

Scan with your phone to open this page

Rating No ratings yet

Supercharge your applications with the ultimate guide to asynchronous and multithreaded programming in C#! C# Concurrency teaches you how to write effective multithreaded and asynchronous software in C#. Practical techniques, real-world examples, and useful code samples cut through the confusion around async/await and help you write rapid, reliable, and bug-free code. In C# Concurrency: Asynchronous and Multithreaded Programming you’ll learn how to: Take full advantage of async/await Write bug-free multithreaded code every time Create multithreaded code that delivers real performance improvements Grok C# and .NET multithreading and asynchronous primitives Know when to use concurrency techniques—and when not to use them! In C# Concurrency Nir Dobovizki, a seasoned C# veteran with over 30 years of high-performance programming experience, shares his deep knowledge and expert techniques. Say goodbye to frustrating pitfalls and impossible-to-find bugs that slow down your applications. Nir's careful approach will teach you how to navigate these challenges with ease, allowing you to achieve lightning-fast performance like never before!

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical, hard-won guide to writing correct and fast concurrent C# code: it explains how async/await and multithreading really work under the hood, when to use each, and how to avoid the bugs that make concurrent code so painful. Best for intermediate C#/.NET developers who already write application code but find async/await and threads confusing or dangerous. 【Book Arc】 - **Opening (~0%–10%)**: Frames the whole problem — what multithreading and asynchronous programming actually are, why multicore CPUs and cloud economics make them essential, and how the compiler rewrites your code (lambdas, yield return) before async/await enters the picture. - **Early (~10%–30%)**: Builds the async/await foundation — Task and Task<T>, how await suspends and resumes, async void, ValueTask — then moves into multithreading basics: threads, the thread pool, Task.Run, shared data, locks, and deadlocks. - **Middle (~30%–55%)**: Connects the two worlds — where code runs after await, locks inside async code, UI threads, and the real trade-offs of async/await (it is contagious, edge-case-heavy, and not free). Also catalogs classic pitfalls: partial updates, memory reordering, deadlocks, race conditions, starvation. - **Late (~55%–80%)**: Advanced practice — processing sequences in the background (Parallel, work queues, BlockingCollection), cancellation with CancellationToken and timeouts, awaiting your own events via TaskCompletionSource, controlling which thread continuations run on (ConfigureAwait, Task.Yield, schedulers), and handling exceptions in async code. - **Ending (~80%–100%)**: Thread-safe collections and building your own asynchronous collection-like components, rounding out the toolkit for real production concurrency. 【Key Takeaways】 - **Multithreading and async solve different problems** (Early): multithreading lets a computer appear to do many things at once; async keeps the CPU productive during waits. Combining them is what lets servers handle thousands of clients. - **Async/await is widely used but poorly understood** (Early): the author's interviews and consulting experience show most developers cannot explain how it works — this book treats that gap as the root cause of production bugs. - **Concurrency has a real cost, so know when not to use it** (Middle): async is contagious, has more edge cases, and is expensive; the book repeatedly stresses choosing concurrency deliberately rather than by default. - **Classic pitfalls are predictable and avoidable** (Middle): partial updates, memory access reordering, deadlocks, race conditions, and starvation each get concrete avoidance strategies rather than vague warnings. - **Cancellation and timeouts are first-class design concerns** (Late): CancellationToken, exception-based cancellation, callbacks, and combined cancellation methods are presented as standard building blocks for background work. - **You can await your own events** (Late): TaskCompletionSource lets you adapt old APIs, wait for initialization, and build asynchronous data structures — extending async beyond built-in operations. - **Thread placement after await is controllable** (Late): synchronization contexts, ConfigureAwait(false), Task.Yield, and task schedulers determine where continuations run, which matters especially for UI apps. - **Exceptions behave differently in async code** (Late): AggregateException handling, lost exceptions, and async void methods are called out as debugging traps worth studying carefully. 【Reading Tips】 - Read Part 1 (chapters 1–7) carefully if you are shaky on async/await internals; the pizza-and-web-server analogy in chapter 1 is the conceptual anchor for everything later. - Skim the compiler-rewriting chapter if you already understand lambdas and yield return, but do not skip the async/await mechanics chapter — it is the book's core. - Treat the pitfalls chapter as a checklist to revisit when debugging real concurrency bugs rather than memorizing it in one pass. - Deep-read the chapters on cancellation, TaskCompletionSource, and ConfigureAwait when you start writing production background services or UI code. - Keep the code samples (available via liveBook and the author's GitHub) open alongside the text; the book is explicitly example-driven. 【Coverage Limits】 This guide is based on stratified excerpts covering the front matter, table of contents, and early chapters; detailed content of later chapters (thread-safe collections, custom async collections) is inferred from chapter titles and may not reflect the full depth of the book.
Excerpt 1
om    ©2025 by Manning Publications Co. All rights reserved.    No part of this publication may be reproduced, stored in a retrieval system, or transmitted,...
View in text
Excerpt 2
publish my idea of a book, helped with support and feedback. Using a food analogy in the first chapter was his idea. And technical editor Paul Grebenc was th...
View in text
Excerpt 3
1788. Each illustration is finely drawn and colored by hand. In those days, it was easy to identify where people lived and what their trade or station in lif...
View in text
Excerpt 4
ut them soon), we can’t really do two things simultaneously. All the processing parts happen one after the other and are not truly in parallel; however, the...
View in text
Excerpt 5
ming together Let’s jump back to the pizzeria one last time. We can improve our pizza making even more: instead of having the cook actively check the oven, j...
View in text
Excerpt 6
s. ❸ The lambda function becomes a method inside that class. Here, the compiler created a new method and an entirely new class. The local variable was moved...
View in text
Excerpt 7
ed, giving us an illusion of code that suspends and resumes. For the yield return feature to work, we need The code transformation that divided our code into...
View in text
Excerpt 8
background operation and do not carry context related to it. A Task just lets you know when that background operation finishes running (the Task object repre...
View in text
Tags
AI categories
Programming LanguageC++C#
Publish Year: 2025
Language: English
File Format: EPUB
File Size: 1.2 MB