c# - TPL 数据流 SendAsync 结果

标签 c# .net tpl-dataflow

我知道要将数据放入 TPL 数据流目标,我可以使用 PostSendAsync,如果可以将项目放入目标,它将立即返回。我知道 SendAsync 将等待更长的时间来尝试将其放入,但我不确定 SendAsync 返回 false 的含义是什么。

返回 falseSendAsync 是否表示目标(特别是 BufferBlock)已完成并且永远不会接受更多消息?
它有可能稍后开始接受消息吗?

最佳答案

I understand that to put data into an TPL Dataflow target I can use Post or SendAsync

正确

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 returning false.

表示目标 block 此时不能接受消息。

Does SendAsync returning false signal that the target (specifically a BufferBlock) 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/

相关文章:

c# - 使用 TaskCompletionSource 与 BufferBlock<T> 包装事件

c# - 如何在 mysql 中使用 count 函数和文本框在 c# Visual Studio 中显示搜索结果

c# - 将 Expression<Func<T,bool>> 转换为 Expression<Func<T1,bool>> 以便 T 成为 T1 的成员

c# - 带有 ref 对象参数的方法

.net - WCF 4.0 Rest Service 返回内容类型 text/html

c# - 完成 TPL 数据流链

c# - 替换字符串中最后一次出现的单词 - C#

c# - 将构造函数参数传递给 Nunit 基类

c# - 为什么 Split from System.String 不接受字符串作为重载?

c# - 使用 AsObservable 观察 TPL Dataflow block 而不消耗消息