Relative Content

Tag Archive for event

will having an event with subscribers prevent an object from being GC’ed?

I have an object, which has an event which in turn has subscribers.
I know that the subscribing objects won’t get GC’ed since the delegate they stored for the event is connected to them, thus keeping them connected with the object graph, until one explicitly unsubscribes them. This is only logical since otherwise nothing good will happen when the event is fired.

How to write a custom EventHandler class

When I started using Java, I created a custom Event class to mimic C#’s implementation of Events. Since then, I’ve added some other features, like event listener priorities, and cascading events were priorities are respected. Now that I’m using C# again, I wanted to create an eventhandler class, or at least a class that I can use the event keyword with, that incorporated these features. Starting off with, I’ve hit a bit of a brick wall where I can’t subclass EventHandler, being told that it’s a sealed class, and I can only use the event keyword with EventHandler/EventHandler and its subclasses.