Skip to content

jeremybytes/csharp-channels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# Channels

The aim of this project is to provide an overview of Channel<T> in the C# language. The example presented here mirrors a project in Go (golang). For more information, see Go for the C# Developer.

Motivation

I first encoutered channels when looking at Go (golang) several years ago. Channels allow for communication between concurrent operations. In .NET Core 3.0, C# got channels as well -- with Channel<T>.

To compare the usage of channels in C#, this project mirrors a Go (golang) project. This is not an extensive look at channels. It is a brief example of how they can be used.

Project Layout

To build and run the code, you will need to have .NET 5 installed on your machine.

/async contains a console application that uses channels program
/net-people-service contains a service (used by the console application)

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

Running the Service

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

[{"id":1,"givenName":"John","familyName":"Koenig","startDate":"1975-10-17T00:00:00-07:00","rating":6,"formatString":null},  
{"id":2,"givenName":"Dylan","familyName":"Hunt","startDate":"2000-10-02T00:00:00-07:00","rating":8,"formatString":null}, 
{...}]
[1,2,3,4,5,6,7,8,9]
  • 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:
{"id":1,"givenName":"John","familyName":"Koenig","startDate":"1975-10-17T00:00:00-07:00","rating":6,"formatString":null}

The Console Application

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

Articles

A set of articles accompanies this example to walk through how channels are used in conjunction with concurrent (async) operations.

C# Articles:

If you are interested in the Go (golang) sample, there is a set of articles that describe goroutines, channels, WaitGroup, and anonymous functions. Go Articles:

About

Code to explore the basics of Channel<T> in C#.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages