using System.Diagnostics;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
public static async Task Main()
var channel = Channel.CreateUnbounded<int>(new UnboundedChannelOptions{SingleReader=true});
var mem0 = GC.GetTotalMemory(true);
for (int i = 0; i < 10; i++)
var stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 500)
using var cts = new CancellationTokenSource(1);
await channel.Reader.ReadAsync(cts.Token);
catch (OperationCanceledException) { timeouts++; }
var mem1 = GC.GetTotalMemory(true);
Console.WriteLine($"{i + 1,2}) Timeouts: {timeouts,5:#,0},"
+ $" Allocated: {mem1 - mem0:#,0} bytes");