0Pricing
C# Academy · Lesson

System.Threading.Channels

Build producer-consumer pipelines using Channel, ChannelWriter, and ChannelReader for backpressure control.

What Are Channels?

System.Threading.Channels (introduced in .NET Core 3) provides a high-performance, thread-safe producer-consumer queue. Unlike BlockingCollection, Channels are fully async and allocation-efficient — ideal for in-process pipelines.

Creating a Channel

Channels are created with a factory. Choose unbounded (no limit) or bounded (limited capacity with backpressure). The factory returns a Channel<T> with a Writer and a Reader.

using System.Threading.Channels;

// Unbounded: unlimited capacity, no backpressure
var unbounded = Channel.CreateUnbounded<string>();

// Bounded: max 100 items; writer waits when full
var bounded = Channel.CreateBounded<string>(100);

// Bounded with drop-oldest strategy:
var dropping = Channel.CreateBounded<string>(new BoundedChannelOptions(50)
{
    FullMode = BoundedChannelFullMode.DropOldest
});

All lessons in this course

  1. IAsyncEnumerable & await foreach
  2. System.Threading.Channels
  3. ValueTask & Avoiding Allocations
  4. ConfigureAwait & Synchronization Context
← Back to C# Academy