diff --git a/README.md b/README.md index efdb431..e1eeee3 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Extensions for `System.Threading.Tasks.Task`, inspired by [John Thiriet](https:/ - AsyncAwaitBestPractices - An extension method to safely fire-and-forget a `Task`: - `SafeFireAndForget` + - `WeakEventManager` - [Usage instructions below](#asyncawaitbestpractices) - AsyncAwaitBestPractices.MVVM - Allows for `Task` to safely be used asynchronously with `ICommand`: @@ -60,6 +61,21 @@ async Task ExampleAsyncMethod() } ``` +An event implementation that enables the [garbage collector to collect an object without needing to unsubscribe event handlers](http://paulstovell.com/blog/weakevents): +- `WeakEventManager` + +```csharp +readonly WeakEventManager _weakEventManager = new WeakEventManager(); + +public event EventHandler CanExecuteChanged +{ + add => _weakEventManager.AddEventHandler(value); + remove => _weakEventManager.RemoveEventHandler(value); +} + +public void RaiseCanExecuteChanged() => _weakEventManager.HandleEvent(this, EventArgs.Empty, nameof(CanExecuteChanged)); +``` + ### AsyncAwaitBestPractices.MVVM Allows for `Task` to safely be used asynchronously with `ICommand`: