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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.