Artículos relacionados a The Idle Thread: Asynchronous Programming in C# and...

The Idle Thread: Asynchronous Programming in C# and .NET - Tapa blanda

Doorwar, Piyush

 
9798171394431: The Idle Thread: Asynchronous Programming in C# and .NET

Sinopsis

Four seconds of waiting. Eleven milliseconds of work.

That is Skylark in chapter one: a flight-price aggregator that asks three airlines for a fare and holds a thread hostage through almost all of it.

Ten chapters later the same program queries forty carriers inside a two-second budget, streams each price to the browser as it lands, scores fifty thousand itineraries across eight cores, and cancels every outbound call the moment a user closes the tab. At two hundred requests a second its median response time is seventy milliseconds worse than at idle.

One program, rebuilt in the open. Every change comes with a measurement you can reproduce.

Plenty of C# developers type async and await daily and would struggle to say what happens to the calling thread when execution reaches an await, or why a service that looks perfectly healthy quietly stops answering under load. This book replaces pattern matching with a model.


What you'll work through
  • What a thread costs, and the point where adding more of them stops helping
  • What a Task really is, and how a thousand of them run on thirteen threads
  • What the compiler writes when you type await, and how to read the stack traces it leaves behind
  • Task.WhenAll, WhenAny and .NET 9's WhenEach, plus the one small omission that turns a fan-out back into a queue
  • Cancellation, linked tokens, timeouts, and returning partial results when the clock runs out
  • Why .Result deadlocks a WPF app and starves an ASP.NET Core one, and how to recognise starvation from a counters dashboard
  • Where parallelism is the right tool and async has nothing to offer
  • Async in a real service: EF Core, IHttpClientFactory, BackgroundService, channels, IAsyncEnumerable streaming
  • ValueTask and its four rules, ExecutionContext, and what .NET 11's runtime async changes underneath you


Written for developers who already know C# — generics, LINQ, the shape of a .NET project. No prior multithreading experience assumed; chapter two starts from what a thread is.

Code targets .NET 10 LTS, with a closing chapter on .NET 11. A quick-reference appendix collects the combinators, the cancellation API, the diagnostic commands, and a table of anti-patterns with what to write instead.

"Sinopsis" puede pertenecer a otra edición de este libro.