Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Better Parallel Code with C# Channels


Producer/consumer problems show up in a lot of programming scenarios, including data processing and machine learning. Channels were added to .NET Core 3.0 and give us a thread-safe way to communicate between producers and consumers, and we can run them all concurrently. In this presentation, we will explore channels by comparing parallel tasks with continuations to using a producer/consumer model. In the end, we'll have another tool in our toolbox to help us with concurrent programming.

Recorded Presentation: Using Channels in C# to Enhance Concurrent Code - Dot Net North (May 2021)

Project Layout

To build and run the code, you will need to have .NET 7 installed on your machine. The demo project will run wherever .NET 7 will run (Windows, macOS, Linux).

/people-demo/PeopleViewer contains a console application that uses channels program
/people-demo/People.Service contains a service (used by the console application)

The "PeopleViewer" program is a console application that calls the service and displays the output. In order to show concurrency, the application gets each record individually.

Development Environments

Visual Studio 2022
The "ChannelsDemo.sln" contains both of the projects listed above. The solution is set to automatically start both the service and the console application. So, hit "F5" to start the application & service.

Visual Studio Code
In Visual Studio Code, you will want to start the service separately from the command line (see "Running the Service"). You can leave the service running while working with the console application.

Running the Service

The .NET service can be started from the command line by navigating to the ".../people-demo/People.Service" directory and typing dotnet run. This provides endpoints at the following locations:

  • http://localhost:9874/people/1
    Provides an individual "Person" record based on the "id" value. This service will delay for 1 second before responding. Sample record:

The Console Application

The /people-demo/PeopleViewer folder contains a console application that uses channels. The relevant code is in the "Program.cs" file.

Additional Sample

The "digit-display" folder contains an additional code sample. This application is a naive machine learning project that uses concurrent operations and channels. The version included here has a Windows-only user interface.

For more additional information on this project (as well as a set of console applications that run cross-platform), visit the the main repository for the "digit-display" project:

Github: jeremybytes/digit-display


Additional Repositories


Code samples, slides, and links for "Better Parallel Code with C# Channels"







No releases published


No packages published