TPL Dataflow how to remove the link between the blocks

霸气de小男生 提交于 2019-12-23 09:18:11

问题


I would like to know. How can I remove the link between the blocks? In other words. I want to get opposite of LinkTo.

I want to write a logger based on tlp dataflow.

I wrote this interface and want to delete a subscription for ILogListener when it needed.

public interface ILogManager
{
    void RemoveListener(ILogListener listener);
}

回答1:


When you link blocks:

var link = someSourceBlock.LinkTo(someTargetBlock);

you get a return value that implements IDisposable.

To kill the link, just dispose of that return value:

link.Dispose();

See the .LinkTo documentation (in particular the section about the return statement):

Return Value

Type: System.IDisposable

An IDisposable that, upon calling Dispose, will unlink the source from the target.



来源:https://stackoverflow.com/questions/24631767/tpl-dataflow-how-to-remove-the-link-between-the-blocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!