TPL Dataflow 如何去除块之间的链接 [英] TPL Dataflow how to remove the link between the blocks
问题描述
我想知道.如何删除块之间的链接?换句话说.我想与 LinkTo 相反.
I would like to know. How can I remove the link between the blocks? In other words. I want to get opposite of LinkTo.
我想写一个基于 tlp 数据流的记录器.
I want to write a logger based on tlp dataflow.
我写了这个接口,想在需要的时候删除对 ILogListener 的订阅.
I wrote this interface and want to delete a subscription for ILogListener when it needed.
public interface ILogManager
{
void RemoveListener(ILogListener listener);
}
推荐答案
链接块时:
var link = someSourceBlock.LinkTo(someTargetBlock);
你得到一个实现 IDisposable
的返回值.
you get a return value that implements IDisposable
.
要终止链接,只需处理该返回值:
To kill the link, just dispose of that return value:
link.Dispose();
请参阅.LinkTo
文档(特别是关于 return 语句的部分):
See the .LinkTo
documentation (in particular the section about the return statement):
返回值
类型:System.IDisposable
Type: System.IDisposable
一个 IDisposable,在调用 Dispose 时,将取消源与目标的链接.
An IDisposable that, upon calling Dispose, will unlink the source from the target.
这篇关于TPL Dataflow 如何去除块之间的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!