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

View the Video

 

View other video tutorials

 
Thanks to Orcsweb for hosting my website (http://www.xmlforasp.net) and for giving me space to host videos!  If you're looking for a host I highly recommend them.  You won't find better service anywhere.

Published Wednesday, January 17, 2007 11:35 PM by dwahlin
Filed under: , ,

Comments

# re: Video: Creating Custom Events and Delegates with C#

Tuesday, January 30, 2007 4:46 PM by Will

Great example. Now how would you call it asynchronously so it dosen't lock up the UI?

# re: Video: Creating Custom Events and Delegates with C#

Tuesday, January 30, 2007 10:42 PM by dwahlin

There are several different ways to do that including delegates, spawning your own threads, etc., but the easiest way (IMHO) is to use the BackgroundWorker control built into .NET V2 Windows Forms.

# re: Video: Creating Custom Events and Delegates with C#

Thursday, February 1, 2007 8:29 AM by Will

Can you give me an example? I have found a bunch of stuff about backgroundworker but can't seem to get it to work on a class from a different code file than the form.

# re: Video: Creating Custom Events and Delegates with C#

Friday, February 2, 2007 12:06 PM by dwahlin

If I get a chance I'll post a sample but in all honesty it probably won't happen soon due to other priorities I have right now.

# re: Video: Creating Custom Events and Delegates with C#

Sunday, March 18, 2007 6:31 PM by Nisar Khan

thanks for the video and wondering can be used same for asp.net ?

Thanks.

# re: Video: Creating Custom Events and Delegates with C#

Monday, March 19, 2007 11:06 PM by dwahlin

ASP.NET doesn't deal well with callbacks since a callback method may be called after the page's lifecycle has finished and it renders.  So, you'll need to look at other options such as WaitHandles, Polling or the new Async attribute on the Page directive used in conjunction with PageAsyncTasks.  You'll find some info on this and samples if you search my blog for Asynchronous Web Services.