Weak events in .NET?

后端 未结 9 1978
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 16:37

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 s

9条回答
  •  失恋的感觉
    2020-12-04 17:18

    Dustin's implementation only works with EventHandler delegates. If you head over to CodePlex there's a project called Sharp Observation in which the author has built a very good weak delegate provider. It's implemented in MSIL and is considerably faster and more flexible.

    ... which, until Microsoft implement weak events natively, will have to do.

提交回复
热议问题