自定义发布/订阅事件以及在 Winforms 中构建 .Net 事件
我必须设计并实现自己的发布订阅事件以满足动态 UI Winform 设计的要求。 是否有任何支持 pub/sub 的 .Net 库可供我比较并改进?
I had to design and implement my own publish subscribe eventing to satisfy the requirements of a dynamic UI Winform design. Is there any .Net library that supports pub/sub out there that I can compare mine and improve?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不从这个基于列表的发布/订阅模式开始(使用MSDN 上的 WCF)?
Why not start with this list-based publish/subscribe pattern (using WCF) on MSDN?
事实上我走得更远。 例如,您可以创建一个 SystemEvent 并将其发布到名称为“Application.UI.TreeInstance.[InstanceName].Node.Clicked”的主题上,并且如果您注册了“Application.”或“Aplication.Clicked”之类的内容。 UI.' 或 'Application.UI.TreeInstance.[InstanceName].Node.*' 或您将通过多播在委托上调用的完整主题并接收事件。 您可以根据需要定义SystemEvent; 它有一个 ValueNamePairCollection 和一个公共接口,可以根据需要获取数据。 您可以注册同步和异步处理,当然也可以取消注册。 我的 UI 元素现在处理它们关心的事件,而无需知道谁发布了它们。
如果社区对这样的东西感兴趣,我可以打包代码并提供它,以便我们大家可以共享和改进。 我已经对其进行了彻底的测试,并且 100% 有效。我还编写了一些监控 GUI,您可以实时查看发布和订阅以及注册和注销的情况。
Actually I went further than that. For example you can create a SystemEvent and publish it on a subject with a name of 'Application.UI.TreeInstance.[InstanceName].Node.Clicked' and if you register for anything like 'Application.' or 'Aplication.UI.' or 'Application.UI.TreeInstance.[InstanceName].Node.*' or the full subject you will get called on your delegate through multicast and receive the event. The SystemEvent you can define as you want; it has a ValueNamePairCollection and a public interface to get the data out as you feel like. You can register for synchonous and asynchronous processing and offcourse Unregister as well. My UI elements now process events that they care without having to know who publishes them.
If the community has any interest in stuff like this I could package up the code and make it available so we can all share and improve. I have tested it thoroully and works 100%.Also I wrote some monitoring GUI that you can see in real time what is happening with publications and subscriptions as well as registrations and unregistrations.