Skip to content

Commit

Permalink
Added WeakEventManager
Browse files Browse the repository at this point in the history
  • Loading branch information
brminnick committed Dec 16, 2018
1 parent 0ac540a commit 292df67
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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`:
Expand Down

0 comments on commit 292df67

Please sign in to comment.