Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/byjrk/csharpchanneldemo
A simple demo of how to use UnboundedChannel in C#
https://github.com/byjrk/csharpchanneldemo
Last synced: 2 months ago
JSON representation
A simple demo of how to use UnboundedChannel in C#
- Host: GitHub
- URL: https://github.com/byjrk/csharpchanneldemo
- Owner: BYJRK
- Created: 2023-12-07T06:35:50.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-07T06:36:55.000Z (about 1 year ago)
- Last Synced: 2023-12-07T07:32:16.732Z (about 1 year ago)
- Language: C#
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Channel Demo
本项目旨在演示 C# 中 `Channel` 的基本用法。
查看 commit 提交历史可以看到每一步的变化:
1. 使用传统的线程(`Thread`)与阻塞集合(`BlockingCollection`)
2. 将阻塞集合修改为 `Channel`,并仍然使用同步方法
3. 使用异步方法,并使用 `CancellationToken` 来取消接收任务
4. 使用 `ChannelWriter.Complete` 方法取代 `CancellationToken`
5. 使用 `await foreach`,即 `IAsyncEnumerable` 接口取代对于 `Completed` 状态的观察及 `ChannelClosedException` 异常的捕获