MSDN documentation显示DataflowBlockOptions类上有一个NameFormat属性,描述如下:
Gets or sets the format string to use when a block is queried for its name.
那么……你怎么设置这个名字?这个名字怎么样?什么时候使用?
或者……正如我怀疑的那样……这只是一个实际上没有实现的设计残余?
解决方法
你没有设置名称,你设置一个最终会产生名称的
NameFormat
(你当然可以忽略这些参数并设置你想要的任何东西,如NameFormat =“bar”).您可以使用ToString获取名称,例如:
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());
输出:
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.
如果我们看一下source code on .Net Core,ToString实现基本上是:
return string.Format(options.NameFormat,block.GetType().Name,block.Completion.Id);