Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created January 3, 2010 01:50
Show Gist options
  • Save chaliy/267772 to your computer and use it in GitHub Desktop.
Save chaliy/267772 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
TestEvents test = new TestEvents();
var ff = new EventHandler<EventArgs>((s, e) => Console.WriteLine("Test"));
test.SomethingOccured += ff;
test.SomethingOccured += ff;
test.SomethingOccured -= ff;
test.FireSomethingOccured();
}
public class TestEvents
{
private readonly EventHandlerList _events = new EventHandlerList();
private readonly static object SomethingOccuredEvent = new object();
public event EventHandler<EventArgs> SomethingOccured
{
add
{
_events.AddHandler(SomethingOccuredEvent, value);
}
remove
{
_events.RemoveHandler(SomethingOccuredEvent, value);
}
}
public void FireSomethingOccured()
{
var somethingOccured = _events[SomethingOccuredEvent] as EventHandler<EventArgs>;
if (somethingOccured != null)
{
somethingOccured(this, EventArgs.Empty);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment