Back to course

Events and Handlers

C# Zero to Hero: Comprehensive Programming Masterclass

Events in C#

Events enable a class or object to notify other classes when something of interest occurs.

Publisher and Subscriber

  • Publisher: The class that sends the event.
  • Subscriber: The class that receives/handles the event.

Example (Conceptual)

csharp public event EventHandler ProcessCompleted;

protected virtual void OnProcessCompleted() { ProcessCompleted?.Invoke(this, EventArgs.Empty); }