Video: Creating Custom Events and Delegates with C#
It's no secret that events and delegates play a crucial role in the .NET framework. Without them it would be hard to handle user input or notify other objects when an action occurs. I get a lot of questions about events and delegates in classes I teach so I decided to put together a video that outlines the fundamentals of creating a custom class that exposes an event and a delegate. The video also demonstrates how to create a custom EventArgs class and how events can be consumed using C#. The code shown in the video can be downloaded here.

Reader Comments (15)
Right-click on the link [Click here to view in Windows Media Player] and choose "Save Target As..." from the context menu.
This lets you save the .WMV file to your computer.
Nice example. You could even leave out the line where you define the StageCompletedHandler, by using generic EventHandles (.NET 2.0).
Then instead of using:
public event StageCompletedHandler StageCompleted;
you can do this:
public event EventHandler<StageCompletedEventArgs> StageCompleted;
As far as the comment about protected with OnEventName, you're quite right. I caught that after the video was made but didn't want to go back and re-do it again to be honest since it takes some time to get right. :-)
I had the last step everytime wrong. But now I know, how is running. Thanks so lot.
Horanyi
At last time I couldn't do that event handale as customizly.but after seen this vid I can do that.So it is very usefull for me.so thanks a lot
Anushka K Rajasingha
thanks
Read through several books to understand what delegates are. All were confusing.
This video clarified everything.
Thanks a lot.
One thought - I needed to implement this for a web user control I had built, and as referenced above the event came along AFTER the page had finished rendering. I sorted that by resetting the event handlers in the Page_Load event, which is called before the event is serviced in the control. I'm sort-of nervous about this, however it appears to work just fine and is a heck of a lot simpler than using async methods.
Good job - well done! Andrew
Everything now seems to be working normally (i.e. like eveything else does in C#).
Well done!.
-W