var dataBlock = new TransformBlock(i => i * 2); var outputBlock = new ActionBlock (i => Console.WriteLine(i)); dataBlock.LinkTo(outputBlock); dataBlock.Post(1);
var cancellationSource = new CancellationTokenSource(); var block = new ActionBlockIn this example, we create an ActionBlock that takes an integer and prints it to the console. We set a CancellationToken for the block, which allows us to cancel the block at any time. We use the Post method to send the value 1 to the block, and then immediately cancel it. Package library: System.Threading.Tasks.Dataflow.(i => Console.WriteLine(i), new ExecutionDataflowBlockOptions { CancellationToken = cancellationSource.Token }); block.Post(1); cancellationSource.Cancel();