I have this code snippet:
static void Main(string[] args)
{
var printResult = new ActionBlock<int>(x =>
{
Console.WriteLine(x);
});
var countBytes = new TransformBlock<int, int>(
new Func<int, int>((x)=> { return 2 * x; }));
countBytes.LinkTo(printResult, new DataflowLinkOptions { PropagateCompletion = true });
countBytes.Completion.ContinueWith(delegate { printResult.Complete(); });
countBytes.Complete();
printResult.Completion.Wait();
Console.ReadKey();
}
I expected that the TransformBlock
code of
return 2*x
will run, and then print the result, but in fact, nothing is printed. I set a break point inside the
printResult
function object on the Console.WriteLine
but it was not stepped in.
Why nothing is printed, where did I get wrong and how to fix it?