How to drop a data
-
2012年4月16日 上午 07:10
Hello.
I have 3 blocks:
TransoftmBlock b1,b2;
ActionBlock b3;b1.LinkTo(b2); b2.LinkTo(b3);
In some cases I want to drop operation:
b1 gets error during operation, and I want to correctly drop this message, but I cant found how to do it: I need to pass null and b2 and b3 needs to correctly handles this invalid messages.
I really need way to drop operation in some cases, but how to do it?
Thanks!
所有回覆
-
2012年4月16日 下午 01:32
I can see two options here:
- Use
the overload of LinkTo() that takes a predicate. Something like
b1.LinkTo(b2, x => x != null);
- Use TransformManyBlock instead of your TransformBlock and produce a sequence containing only the single result on success and an empty sequence on failure.
- 已編輯 svick 2012年4月16日 下午 01:32
- Use
the overload of LinkTo() that takes a predicate. Something like
-
2012年4月16日 下午 04:11擁有者
Both of your approaches are reasonable. For #1, you can subsequently link b1 to DataflowBlock.NullTarget, such that any data that isn't consumed by b2 will be dropped.
- 已提議為解答 Stephen Toub - MSFTMicrosoft Employee, Owner 2012年4月16日 下午 04:11
- 已標示為解答 Stephen Toub - MSFTMicrosoft Employee, Owner 2012年4月27日 上午 10:28

