Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 此块只能与创建它的源一起使用_.net_Task Parallel Library_Tpl Dataflow - Fatal编程技术网

.net 此块只能与创建它的源一起使用

.net 此块只能与创建它的源一起使用,.net,task-parallel-library,tpl-dataflow,.net,Task Parallel Library,Tpl Dataflow,我将TPL数据流用于此初始网络: (a)CustomSource => (b)TransformBlock 当消息到达b时,b使用过滤器创建一个新的转换块,并将其附加到自身(对于每条消息并不如此) 网络变成这样: (a)CustomSource => (b)TransformBlock => (c with linkto filter)TransformBlock (a)CustomSource => (b)TransformBlock => (c w

我将TPL数据流用于此初始网络:

(a)CustomSource => (b)TransformBlock
当消息到达b时,b使用过滤器创建一个新的转换块,并将其附加到自身(对于每条消息并不如此)

网络变成这样:

(a)CustomSource => (b)TransformBlock => (c with linkto filter)TransformBlock
(a)CustomSource => (b)TransformBlock 
    => (c with linkto filter)TransformBlock
    => (c with another linkto filter)TransformBlock
    => (c with another linkto filter)TransformBlock
运行几次后,网络会变成这样:

(a)CustomSource => (b)TransformBlock => (c with linkto filter)TransformBlock
(a)CustomSource => (b)TransformBlock 
    => (c with linkto filter)TransformBlock
    => (c with another linkto filter)TransformBlock
    => (c with another linkto filter)TransformBlock
这很好,是我找到的唯一一个为“开关”块获得默认操作的解决方案

但是,当通过调用customSource.Complete()完成源时,它会抛出一个异常:

ArgumentException:此块只能与创建它的源一起使用 在System.Threading.Tasks.Dataflow.DataflowBlock.FilteredLink传播器
1.System.Threading.Tasks.Dataflow.ITargetBlock.OfferMessage(DataflowMessageHeader messageHeader,T messageValue,ISourceBlock
1源,布尔值consumeToAccept) 在System.Threading.Tasks.Dataflow.Internal.SourceCore
1.OfferMessageToTarget(DataflowMessageHeader标头、TOutput message、ITargetBlock
1目标、布尔值和消息被接受) 在System.Threading.Tasks.Dataflow.Internal.SourceCore
1.OfferTargets(ITargetBlock
1 linkToTarget) 位于System.Threading.Tasks.Dataflow.Internal.SourceCore`1.OfferMessageLoopCore()


其中一个“c”转换块出现故障。当一个块出现故障时,它不会自动与网络断开链接。添加完成任务以取消区块链接似乎可以解决此问题。

能否发布一个简短的代码来重现此问题?我的猜测是,您试图将来自
CustomSource
的消息直接提供给
LinkTo
过滤器,但我不知道您会怎么做。我想我发现了问题。其中一个“c”转换块出现故障。当一个块出现故障时,它不会自动与网络断开链接。添加一个完成任务以取消块的链接似乎可以解决此问题。顺便说一句,“c”TransformBlock会出现故障,因为它使用筛选器链接到一个子块,但筛选器始终返回false。TPL数据流似乎没有丢弃消息,而是对块进行故障处理。我使用的是.NET4.5测试版中包含的版本。