I would like to create some functionality like Timer.CallLater for an event system.
Currently, I return a key for each subscription to the event so that it can be cleaned up later by a call to unsubscribe. This requires me to keep a key in every object that uses the event system. The more places I use the system the more chances I get something wrong by not recording or releasing the key correctly.
I tried to use just the delegate returned from the AddressOf as the key to a dictionary, however, it does not seem to equal the previous call so it cannot be used in Dictionary.Remove(key). I was able to get something working by converting the delegate to a ptr, but then the object reference is stripped making it useless for multiple objects calling subscribe with the same method.
How does Timer.CallLater handle this with calls from different objects?
Is there a way to get the object reference from the delegate or find equality between 2 calls to AddressOf on an object method?
Thanks!
6 posts - 4 participants