Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set/get/use the name of a block in TPL Dataflow?

MSDN documentation shows that there is a NameFormat attribute on the DataflowBlockOptions class, described as:

Gets or sets the format string to use when a block is queried for its name.

So ... how do you set the name? How is the name available? When is it used?

Or ... as I suspect ... is this just a remnant of design that didn't actually get implemented?

like image 645
davidbak Avatar asked Jun 28 '14 17:06

davidbak


1 Answers

You don't set the name, you set a NameFormat that will eventually result in a name (you can of course disregard the parameters and set whatever you want like NameFormat = "bar") . You may get the name by using ToString, for example:

var block = new ActionBlock<int>(_ => { }, new ExecutionDataflowBlockOptions
{
    NameFormat = "The name format may contain up to two format items. {0} will be substituted with the block's name. {1} will be substituted with the block's Id, as is returned from the block's Completion.Id property."
});

Console.WriteLine(block.ToString());

Output:

The name format may contain up to two format items. ActionBlock`1 will be substituted with the block's name. 1 will be substituted with the block's Id, as is returned from the block's Completion.Id property.


If we look at the source code on .Net Core the ToString implementation is basically:

return string.Format(options.NameFormat, block.GetType().Name, block.Completion.Id);
like image 143
i3arnon Avatar answered Oct 02 '22 21:10

i3arnon