Pages

Topics

Tools

↑↓navigate↵openescclose

C# guides

Every published C# guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest C# guides

Diagram showing a ValueTask struct returning a value directly versus wrapping a Task, with an arrow indicating reduced allocation.
C#

C# ValueTask: When and How to Use It

C# ValueTask can reduce async allocations in hot paths, but it is not a drop-in replacement for Task. Learn when to use it, when to avoid it, and how to avoid common pitfalls.

ValueTaskasync/awaitperformanceC#
Illustration of a C# async method with ConfigureAwait controlling whether the continuation returns to the UI thread or runs on the thread pool.
C#

C# ConfigureAwait: When and Why to Use It

Understand what C# ConfigureAwait does, when to use ConfigureAwait(false) in async libraries, and why UI code should keep the default await behavior to avoid context-capture pitfalls.

async-awaitSynchronizationContextdeadlock.NET
Diagram showing a C# Task.Delay timer completing asynchronously without blocking the calling thread.
C#

C# Task.Delay: Async Timing Without Blocking Threads

Practical C# Task.Delay guide covering async usage, cancellation, overload selection, runtime behavior, and common mistakes to avoid.

Task.Delayasync-awaitcancellationtimers
Illustration of multiple asynchronous tasks racing, with the first completed one highlighted as Task.WhenAny in C#.
C#

C# Task.WhenAny: Handling the First Completed Task

Learn how to use C# Task.WhenAny to await the first completed task, handle timeouts, filter for the first successful result, and manage cancellation.

C#asyncconcurrencyTask.WhenAny
Illustration of multiple asynchronous tasks merging into a single await point in C#
C#

C# Task.WhenAll: Awaiting Multiple Tasks

Use C# Task.WhenAll to await multiple independent asynchronous operations, collect their results, observe exceptions, and control concurrency.

C#asyncTask.WhenAllconcurrency
Comparison of await and Task.Result in C# showing a deadlock risk
C#

C# await vs Task.Result: Avoid Blocking Async Code

c# await vs task result: Understand the difference between await and Task.Result in C#, why blocking on async tasks can cause deadlocks, and when it's acceptable.

async/awaitTaskdeadlockthread pool
Illustration of a C# Task returning a value, showing the flow from an async operation to the awaited result.
C#

C# Task Result: How to Access Values from Async Methods

Learn how to access a C# Task<T> result with await, .Result, and GetAwaiter().GetResult(), including exception handling and deadlock avoidance.

async/awaitTask<T>concurrency.NET
Diagram contrasting async void and async Task in C#, showing exception flow and awaitability
C#

C# async void vs Task: Key Differences

C# async void vs Task: learn how their exception behavior and awaitability differ, when async void is required, and why async Task is the safer default.

asyncC#Taskexception handling
Illustration of an async void method with an unhandled exception causing an application crash, showing a broken chain link.
C#

c# async void: Exception Risks and Safe Patterns

Learn how c# async void behaves, why it can crash your app, and when it's acceptable to use in event handlers.

async-voidC#exception-handlingevent-handlers
Illustration of a C# async task showing a method returning a Task that is awaited, with a timeline of execution and a synchronization context.
C#

Using C# async Task: Async/Await in Practice

Learn how to use C# async Task effectively: declaring async methods, awaiting tasks, handling errors, avoiding common pitfalls, and understanding performance tradeoffs.

asyncawaitTaskconcurrency