### Illustrating Open-Instance Delegates in C# Source: https://github.com/thomaslevesque/weakevent/blob/master/README.md This snippet provides an example comparing a standard delegate signature with an open-instance delegate signature. Open-instance delegates include an extra parameter for the target instance, which is used internally by WeakEventSource to invoke subscriber methods without holding a strong reference to the target. ```csharp public delegate void FooEventHandler( object sender, FooEventArgs e); public delegate void OpenFooEventHandler(object target, object sender, FooEventArgs e); ``` -------------------------------- ### Declaring a Weak Event using WeakEventSource in C# Source: https://github.com/thomaslevesque/weakevent/blob/master/README.md This snippet demonstrates how to declare an event using the WeakEventSource class. It involves creating a private instance of WeakEventSource and implementing the event's add and remove accessors to delegate subscription and unsubscription to the WeakEventSource instance. ```csharp private readonly WeakEventSource _myEventSource = new WeakEventSource(); public event EventHandler MyEvent { add { _myEventSource.Subscribe(value); } remove { _myEventSource.Unsubscribe(value); } } ``` -------------------------------- ### Standard C# Event Declaration Source: https://github.com/thomaslevesque/weakevent/blob/master/README.md This snippet shows the typical way to declare an event in C#. This standard approach creates a strong reference from the publisher to the subscriber via the delegate, which can prevent the subscriber from being garbage collected unless explicitly unsubscribed. ```csharp public event EventHandler MyEvent; ``` -------------------------------- ### Raising a Weak Event using WeakEventSource in C# Source: https://github.com/thomaslevesque/weakevent/blob/master/README.md This snippet shows how to raise an event that has been declared using WeakEventSource. Instead of directly invoking the event field, you call the Raise method on the WeakEventSource instance, passing the sender and event arguments. ```csharp private void OnMyEvent(MyEventArgs e) { _myEventSource.Raise(this, e); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.