How to pass Task results to other Tasks not using continuations
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In modern C#, you usually do not need explicit continuations to pass the result of one Task into another. await already gives you a clean way to wait for a result and feed it into the next async step, and for more advanced pipelines you can use channels or TaskCompletionSource.
The Simplest Pattern: await Then Call the Next Method
If task B depends on the result of task A, write that dependency directly in code. This is clearer than ContinueWith and respects normal exception flow.
This is the direct replacement for most continuation-based code. The result is explicit, exceptions are propagated naturally, and the control flow is easy to debug.
Encapsulate the Whole Pipeline in One Async Method
If several tasks form one logical operation, hide the chaining inside a single async method rather than making callers stitch tasks together manually.
This pattern keeps dependent async work in one place and avoids exposing intermediate plumbing to the rest of the application.
Passing Results Between Independent Tasks
If one task produces values over time and another task consumes them, a channel is usually a better fit than continuations. A Channel<T> gives you safe producer-consumer flow with backpressure support.
This is a good answer when "pass results to another task" means ongoing communication rather than a single handoff.
When TaskCompletionSource Makes Sense
TaskCompletionSource<T> is useful when another part of the system decides when a task completes. It is not the first tool to reach for, but it can bridge event-based or callback-based code into the task world.
One task can await WaitForResultAsync, while another part of the code publishes the value later. This avoids ContinueWith, but it should be used intentionally because manual task completion adds complexity.
Choosing the Right Tool
Use await when the dependency is simple and sequential. Use a channel when tasks exchange a stream of results. Use TaskCompletionSource<T> when you need an externally controlled completion signal. Most codebases are better when continuation chains disappear and business logic becomes normal async methods with explicit inputs and outputs.
Common Pitfalls
- Replacing
ContinueWithwithTask.Resultcan deadlock or block threads unnecessarily. - Starting background tasks just to pass one value often makes the code harder to reason about.
- Using
TaskCompletionSource<T>for ordinary sequencing adds manual state management you do not need. - Forgetting to propagate cancellation tokens makes task pipelines harder to stop cleanly.
- Swallowing exceptions inside fire-and-forget tasks hides failures from the caller that needed the result.
Summary
- Use
awaitfor the normal case where one task depends on another task's result. - Wrap multi-step async flows in a single async method to keep the API clean.
- Use
Channel<T>for producer-consumer patterns that exchange many results. - Use
TaskCompletionSource<T>only when completion must be controlled externally. - Prefer explicit async composition over continuation chains for readability and error handling.
Related reading
- How to pass the UI Dispatcher to the ViewModel
- How to pause / sleep thread or process in Android?
- How to Pause and Resume the Task which runs Asynchronously
- How to perform an async task against es6 generators in loop
- How to play a sound in C, .NET
- How to preserve HttpContext in Web API async task
- How to perform async initalization of lazy injection
- How to perform multiple asynchronous requests starting one after another

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.