advanced · 29 minute study
A Task represents completion, not a promise of another thread
Keep a UI responsive and a server from blocking unnecessarily while making asynchronous failures visible to the caller.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Model absence before deciding whether to throw — A missing value, a rejected input and a broken dependency are different outcomes. Model them so callers can respond deliberately.
First, build a mental model
An async method runs until it reaches an await that must suspend. Its Task represents eventual completion. Awaiting lets the method resume when the result is available; asynchronous work and parallel CPU work are different concepts.
- Task represents completion without a result; Task<T> also represents a typed result.
- Calling an async method does not automatically create a dedicated background thread.
- await observes completion and propagates failure. Blocking with Result or Wait can waste threads and can deadlock in some synchronization contexts.
- For independent operations, start both then await Task.WhenAll; do not overlap operations that have an ordering dependency.
static async Task<int> ReadScoreAsync()
{
await Task.Delay(10);
return 7;
}
Task<int> pending = ReadScoreAsync();
Console.WriteLine("started");
int score = await pending;
Console.WriteLine(score);- Start
The method begins and returns a Task representing its eventual completion.
- Caller continues
The caller prints started before it prints the awaited result.
- Resume
After pending completes, await yields 7 and the next line prints it.
Production thinking
Take this beyond the example.
Return Task from application methods so callers can await failures; reserve async void for the event-handler situations that require it. Use bounded concurrency and measure throughput rather than creating unlimited work.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · Cancellation is a request; stale results still need a guard →