I am trying to use action block to execute some tasks. My question is when the CreateActionBlock()
method finishes, the ActionBlock
is still processing the data. Since the method is returned and I do not have a way to call actionBlock.Complete()
. Will it cause any problems if I run this CreateActionBlock()
thousand times? Will there be thousand of actionBlocks forever in the memory or they will be GC'ed after the 5 inputs processed?
private static async Task Dequeue(string content)
{
Console.WriteLine("The string is " + content);
await Task.Delay(10000);
}
public static void CreateActionBlock()
{
var actionBlock = new ActionBlock<string>(
(e) => Dequeue(e),
new ExecutionDataflowBlockOptions()
{
BoundedCapacity = 5,
MaxDegreeOfParallelism = 1
});
for (int i = 0; i < 5; i++)
{
actionBlock.Post(i.ToString());
}
}