Chapter 12: Asynchronous programming
In this chapter
- 12.1 The essence of asynchrony
- I/O bound vs. CPU bound
- 12.2 Deep dive into async/await
- State machine
- Runtime Async: saving state in the runtime (.NET 11)
- 12.3 Task and
Task<T>- Starting asynchronous operations
- Waiting for operations to complete
- Task.WhenAll and parallel execution
- Task.WhenAny and timeout handling
- Task.WhenEach: process completed tasks one by one (.NET 9+)
- 12.4 ValueTask: reducing allocations on synchronous completion paths
- When to use
- Usage constraints
- 12.5 IAsyncEnumerable and async streams
- Reading async streams: await foreach
- 12.6 Deadlocks and ConfigureAwait
- Sync over async deadlock
- ConfigureAwait(false)
- 12.7 Asynchronous cancellation
- 12.8 Progress reporting
- Why not use
Action<T>directly? - Using
IProgress<T> - Custom progress types
- Why not use
- 12.9 Async disposal
- await using
- Implementing your own
IAsyncDisposable
- 12.10 AI-assisted development: review asynchronous control flow
- Analyze blocking and deadlock risks
- Review cancellation and resource lifetimes
- Summary
- Glossary
This chapter is not available in the free preview. Purchase the book to read the complete edition now.