using System;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static async Task Main(string[] args)
{
//==============================================节流队列==============================================
//场景生产者比消费者运行得快,会造成不必要的内存使用,如希望保留所有的对象项,则建议使用节流队列
Channel<int> queue = Channel.CreateBounded<int>(1);
ChannelWriter<int> writer = queue.Writer;
ChannelReader<int> reader = queue.Reader;
await
C# System.Threading.Channels节流队列和采样队列,当消费者速度赶不上生产者时建议使用
最新推荐文章于 2024-05-18 01:38:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)