• 07/20/2015 2 minutes to read

In this post

Events make it possible for a class or object to alert other classes or items when something of interest occurs. The class that sends (or raises) the occasion is called the publisher and the classes that receive (or manage) the event are called subscribers.

In a common C# Windows Types or Web application, you subscribe to occasions raised by controls such as buttons and list boxes. You can use the Visual C# incorporated advancement environment (IDE) to browse the events that a control publishes and select the ones that you want to deal with. The IDE provides an easy way to instantly add an empty event handler method and the code to sign up for the occasion. For more information, see How to register for and unsubscribe from events.

Occasions Summary

Occasions have the following homes:

  • The publisher identifies when an occasion is raised; the subscribers determine what action is taken in response to the event.

  • An occasion can have multiple customers. A customer can deal with several events from several publishers.

  • Occasions that have no subscribers are never raised.

  • Events are generally used to signify user actions such as button clicks or menu selections in visual user interfaces.

  • When an occasion has several customers, the occasion handlers are invoked synchronously when an event is raised. To conjure up events asynchronously, see Calling Simultaneous Methods Asynchronously.

  • In the.NET class library, events are based on the EventHandler delegate and the EventArgs base class.

For more information, see:

C# Language Spec

For additional information, see Events in the C# Language Specification. The language spec is the conclusive source for C# syntax and usage.

Included Book Chapters

Delegates, Occasions, and Lambda Expressions in C# 3.0 Cookbook, Third Edition: More than 250 solutions for C# 3.0 programmers

Delegates and Events in Knowing C# 3.0: Master the fundamentals of C# 3.0

See also


Leave a Reply

Your email address will not be published. Required fields are marked *