With the current behaviour, it will cause the HandlerCount of EventStateManager drops to 0, therefore the keyboard event will be turned off with Core_ToggleEvent and Handler2 will not be fired after that.
So, I think it would be better to add a check if HashSet<TEvent>.Add and HashSet<TEvent>.Remove returns a successful result before doing anything with EventStateManager.
Consider this example:
With the current behaviour, it will cause the HandlerCount of EventStateManager drops to 0, therefore the keyboard event will be turned off with
Core_ToggleEvent
and Handler2 will not be fired after that.So, I think it would be better to add a check if
HashSet<TEvent>.Add
andHashSet<TEvent>.Remove
returns a successful result before doing anything withEventStateManager
.