我知道要将数据放入 TPL 数据流目标,我可以使用 Post
或 SendAsync
,如果可以将项目放入目标,它将立即返回。我知道 SendAsync
将等待更长的时间来尝试将其放入,但我不确定 SendAsync
返回 false
的含义是什么。
返回 false
的 SendAsync
是否表示目标(特别是 BufferBlock
)已完成并且永远不会接受更多消息?
它有可能稍后开始接受消息吗?
最佳答案
I understand that to put data into an TPL Dataflow target I can use
Post
orSendAsync
正确
that will return immediately if the item could be put into the target.
不正确 - 其方法都立即返回。如果您使用的是 Post
,它也会返回 false
。
I understand that
SendAsync
will wait longer to try an put it in
部分正确。 SendAsync
将设置一个状态机,最终将返回一个结果。
however I am not certain what is the meaning of
SendAsync
returningfalse
.
表示目标 block 此时不能接受消息。
Does
SendAsync
returningfalse
signal that the target (specifically aBufferBlock
) has finished and will never accept more messages?
这有很多原因,不仅仅是那个目标处于完成状态。例如,它自己的缓冲区可能充满了消息,而另一个缓冲区不适合它(如果您的 block 受 BoundedCapacity
约束)。所以你不能肯定地说方法返回 false
的原因是完成状态。但是,如果您不限制缓冲区的容量,它可能是。
Is it possible that it could start accepting messages later?
不, block 的设计方式是它们只能完成一次。您需要重新创建一个 block 并将其插入管道以重新启动它。
关于c# - TPL 数据流 SendAsync 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45741928/