Examples of how use delegates and events. Above there are some tips of how create, call and use it.
Steps to create a event
- Define a delegate
- Define an event based on that delegate
- Raise the event
Declare an event with parameter
public event Action<Video> VideoEncoded;
Sign the event
videoEncoder.VideoEncoded += messageService.OnVideoEncoded;
videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
Event method
/// <summary>
/// Default protected virtual void Event method
/// Receives a video class and publish the message
/// </summary>
/// <param name="videoName"></param>
protected virtual void OnVideoEncoded(Video videoName) {
// If VideoEncoded delegate is not null
// Call the method who assign them
VideoEncoded?.Invoke(videoName);
}