Making and using events. Make your own events and use them.
Introduction
In this example I made three classes:
1 - class InfoSupplier Exposes its own event which carries some information. For example a Information agency which receives information from its agents and then exposes this information to the TV, news and so on.
public delegate void InfoEventHandler(object source, InfoEventArgs args);
public event InfoEventHandler OnInfoArrivedHandler;
2 - class InfoListener Uses the events which are raised from the InfoSupplier instances. When receives a new event it displays the information which the event has brought. This class has one more special method : void PublishInfo(object source, InfoEventArgs info); which must have the same signature as the delegate declared in the class InfoSupplier.
3 - class InfoEventArgs : EventArgs This is the actual event which is raised and received. It contains one data member, which describes an event. U can put here as much data members as u want, in order to fully describe your event.
This is the idea of using events and it’s the same in Timer events and so on…easy.