在.NET弱的事件? [英] Weak events in .NET?

查看:182
本文介绍了在.NET弱的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果对象A侦听到的对象B的事件,对象B将继续反对为生。 有没有一个标准的实施,将prevent这种弱的事件? 我知道WPF有一定的机制,但我期待的东西不依赖于WPF。 我猜的解决方案应该使用弱引用的地方。

If object A listens to an event from object B, object B will keep object A alive. Is there a standard implementation of weak events that would prevent this? I know WPF has some mechanism but I am looking for something not tied to WPF. I am guessing the solution should use weak references somewhere.

推荐答案

达斯汀·坎贝尔从DidItWith.NET博客探讨一些失败的尝试创建弱的事件处理程序,然后继续表现出有效的工作,轻量级实现: 解决问题的弱事件处理程序

Dustin Campbell from the DidItWith.NET blog examines several of the failed attempts to create weak event handlers, then goes on to show a valid, working, lightweight implementation: Solving the Problem With Weak Event Handlers.

在理想情况下,虽然,微软将推出的概念引入语言本身。是这样的:

Ideally, though, Microsoft would introduce the concept into the language itself. Something like:

Foo.Clicked += new weak EventHandler(...);

如果你觉得这个功能对你很重要,请<一href="https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2542952-weakreference-and-weakevent-operators"相对=nofollow>投赞成票这里。

If you feel this feature is important to you, please vote for it here.

这篇关于在.NET弱的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆