Stopping Invoking the rest of the registered methods if the bool is true
Any possible ways to do it?
11 Replies
By "The rest of the registered methods", do you mean all other methods which were added to that multicast delegate with
+=
?yep
Not directly. Some of the BCL's events, such as this one https://learn.microsoft.com/en-us/dotnet/api/system.windows.routedeventargs.handled?view=windowsdesktop-8.0 have a
Handled
property on the EventArgs. To make that work, they don't invoke the multicast delegate with .Invoke
, but they explicitly get the invocation list (https://learn.microsoft.com/en-us/dotnet/api/system.multicastdelegate.getinvocationlist?view=net-8.0) and call the delegates one by one, checking that Handled
property after each
can't find the "Handled" property
nor get the bool value
I gave you an example of part of the BCL which has defined its own
Handled
property on its EventArgs
subclassif you want that kind of behavior then using multicast delegate seems the wrong tool tbh
actually it seems quite possible depending on if u have control over invoking.
would print
tho, that would be damn slow and causes more allocations
it's possible, but for me it would way better - if possible - to have an object that manages the dispatch and can 'explain' why stuff is going to all or some of the registered handlers
yeah i agree there
is this a bad idea?
besides the
Handled
property u could do it relatively like that.
the event
members have add
and remove
accessors similar to get
and set
for properties:
this way u can still add/remove event handlers like with normal ones