QuickDevGuide

Home › C#

Async / Await — C#

async/await makes asynchronous I/O read like synchronous code. While awaiting, the thread is released to do other work — essential for scalable web APIs. Rules of thumb Do Don't Return Task / Task<T> (or ValueTask on hot paths) async void (except UI event handlers) await all the way up .Result / .Wait() — can deadlock and blocks threads Pass CancellationToken through Ignore cancellation Task.WhenAll for independent work Await independent calls one by one Task.Run for CPU-bound work in UI apps Task.Run around I/O in ASP.NET Core Streams of data IAsyncEnumerable<T> + await foreach processes items as they arrive (paged APIs, database streaming). Parallel.ForEachAsync runs async work with bounded parallelism.

Key Takeaways