TPL 默认构造函数 BufferBlock:DataFlowBlockOptions 的值

TPL default constructor BufferBlock: Value of DataFlowBlockOptions

如果使用默认构造函数构造TPLBufferBlockDataFlowBlockOptions是不是无界的?也就是说,BufferBlockBoundedCapacity是什么?

As stated in this SO answer,构造后BufferBlock的值无法查询,也无法更改。

您有两种选择可以找到答案:阅读 docs 或自己创建 BufferBlock

来自Introduction to TPL Dataflow

The majority of the dataflow blocks included in System.Threading.Tasks.Dataflow.dll support the specification of a bounded capacity.

This is the limit on the number of items the block may be storing and have in flight at any one time. By default, this value is initialized to DataflowBlockOptions.Unbounded (-1), meaning that there is no limit.

However, a developer may explicitly specify an upper bound. If a block is already at its capacity when an additional message is offered to it, that message will be postponed.

此外,来自 MSDN

DataflowBlockOptions is mutable and can be configured through its properties.
When specific configuration options are not set, the following defaults are used:

Dataflow blocks capture the state of the options at their construction.
Subsequent changes to the provided DataflowBlockOptions instance should not affect the behavior of a dataflow block.

您始终可以从调试器查看私有成员:

您也可以尝试 get/set 他们通过反思,但确实不推荐这样做。