.NET/C#
Concurrency - TPL Dataflow
dozob
2023. 8. 16. 23:41
https://www.oreilly.com/library/view/concurrency-in-c/9781492054498/
Concurrency in C# Cookbook, 2nd Edition
If you’re one of many developers still uncertain about concurrent and multithreaded development, this practical cookbook will change your mind. With more than 85 code-rich recipes in this updated second … - Selection from Concurrency in C# Cookbook, 2n
www.oreilly.com
TPL(Task Parallel Library) Dataflow
Nuget Package: System.Threading.Tasks.Dataflow
try
{
var multiplyBlock = new TransformBlock<int, int>(item =>
{
if (item == 1)
throw new InvalidOperationException("Blech.");
return item * 2;
});
var substractBlock = new TransformBlock<int, int>(item => item - 2);
multiplyBlock.LinkTo(substractBlock,
new DataflowLinkOptions { PropagateCompletion = true });
multiplyBlock.Post(1);
substractBlock.Completion.Wait();
}
catch (AggregateException ex)
{
AggregateException agex = ex.Flatten();
Trace.WriteLine(ex.InnerException);
}