Events are a special kind of multicast delegate that can only be invoked from within the class or struct where they are declared (the publisher class). If other classes or structs subscribe to the event, their event handler methods will be called when the publisher class raises the event.

Events enable a 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.


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 called.

  • 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 .

  • Events can be used to synchronize threads.

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


相关文章:

  • 2021-12-11
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-11-15
  • 2021-12-14
猜你喜欢
  • 2021-06-24
  • 2021-07-18
  • 2021-12-29
  • 2021-07-04
  • 2021-05-22
  • 2021-12-19
  • 2021-08-29
相关资源
相似解决方案