C# · Async programming
C# async and await interview questions
An async answer should explain what happens while work waits, which resources remain occupied, and how failure reaches the caller. Start with these four questions.
Published by RoleHello. Technical references are linked below.
Does async create a new thread?
No. An async method runs synchronously until it reaches an await that cannot complete immediately. It then yields to its caller. Awaiting network or database I/O does not require a dedicated thread to sit waiting for the response. A Task represents an operation, not necessarily a thread.
For CPU work, Task.Run can move computation onto a thread-pool thread. That can keep a desktop UI responsive; it does not make the computation cheaper.
Why avoid Result and Wait in an ASP.NET Core request?
They block a thread while the operation completes. With enough simultaneous requests, blocked threads can cause thread-pool starvation and higher latency. Keep the request path asynchronous through to the actual I/O API.
Wrapping blocking work in Task.Run inside a request still consumes a thread. For expensive, long-running work, consider a bounded background queue with a separate completion flow.
When should independent operations run concurrently?
Start independent requests before awaiting their combined result. For example, a dashboard can load its profile and recent activity concurrently:
// client is an injected HttpClient; cancellation comes from the caller.
Task<string> profile = client.GetStringAsync(profileUri, cancellation);
Task<string> activity = client.GetStringAsync(activityUri, cancellation);
string[] responses = await Task.WhenAll(profile, activity);
The example has only two requests. A list of thousands needs a concurrency limit chosen for the downstream service. Measure latency, error rates, and saturation before increasing it. Concurrency is a capacity decision as well as a language feature.
What should happen when a request is cancelled?
Pass the caller’s cancellation token into operations that support it. Cancellation is cooperative: requesting it does not forcibly stop arbitrary code or undo work that already committed. Release owned resources even when cancellation or another exception interrupts the operation.
In an interview, distinguish cancellation from a timeout. Cancellation says the result is no longer wanted; a timeout sets a waiting budget. A payment accepted by another service may still need reconciliation after the client stops waiting.
Try explaining this scenario
A dashboard calls two services. One responds in 80 ms; the other sometimes takes five seconds. Explain which calls can overlap, how you would choose the timeout, and what happens if the user leaves. State whether partial results are acceptable before proposing retries.