Permalink
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (64 sloc) 4.37 KB
title ms.date ms.prod ms.technology ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author translation.priority.ht translation.priority.mt
Events (C# Programming Guide)
2015-07-20
.net
devlang-csharp
article
CSharp
classes [C#], events
C# language, events
events [C#]
a8e51b22-d294-44fb-9539-0072f06c4cb3
43
BillWagner
wiwagn
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
ru-ru
zh-cn
zh-tw
cs-cz
pl-pl
pt-br
tr-tr

Events (C# Programming Guide)

Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.

In a typical C# Windows Forms or Web application, you subscribe to events raised by controls such as buttons and list boxes. You can use the [!INCLUDEcsprcs] integrated development environment (IDE) to browse the events that a control publishes and select the ones that you want to handle. The IDE automatically adds an empty event handler method and the code to subscribe to the event. For more information, see How to: Subscribe to and Unsubscribe from Events.

Events Overview

Events have the following properties:

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

  • An event can have multiple subscribers. A subscriber can handle multiple events from multiple publishers.

  • Events that have no subscribers are never raised.

  • Events are typically used to signal user actions such as button clicks or menu selections in graphical user interfaces.

  • When an event has multiple subscribers, the event handlers are invoked synchronously when an event is raised. To invoke events asynchronously, see Calling Synchronous Methods Asynchronously.

  • In the [!INCLUDEdnprdnshort] class library, events are based on the xref:System.EventHandler delegate and the xref:System.EventArgs base class.

Related Sections

For more information, see:

C# Language Specification

[!INCLUDECSharplangspec]

Featured Book Chapters

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

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

See Also

xref:System.EventHandler
C# Programming Guide
Delegates
Creating Event Handlers in Windows Forms
Multithreaded Programming with the Event-based Asynchronous Pattern