EventHandler and EventArgs

When designing frameworks, consistency is all important to make people feel at home with new APIs quickly. For educational purposes, we’ve approached the concept of events from their essential property: Events are nothing but delegates in disguise. In doing so, we chose simple delegate types for our examples, as follows:

public event Action<uint> Tick;public event Action       Finished;

In practice, it’s more common to follow a certain pattern for events that makes their handlers have a consistent shape. We’ve already seen such a case in passing, when showing off an event handler for a button control’s Click event in Windows Forms:

private void login_Click(object sender, EventArgs e) { ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.