Weak events in .NET?

后端 未结 9 1996
没有蜡笔的小新
没有蜡笔的小新 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:32

    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(...);
    

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

提交回复
热议问题