Prev | Current Page 276 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

As long as the subscribing methods match the delegate signature,
the delegate is happy to add those methods to its invocation list, and it promptly processes
this list each time it is invoked with a call to d().
If you step through this code with the debugger, you will notice that methods on the delegate??™s
invocation list are synchronously called in the order that they are added to the invocation list. The
syntax for adding a delegate to the invocation list may seem strange at first, because what
190 CHAPTER 5 ?–  SE RVER CONTROL EVENTS
we are really adding is something more akin to function pointers than, say, an integer. The magic
behind this is the keyword delegate and the .NET infrastructure provided by the System.Delegate
and System.Delegate.MulticastDelegate classes. The result is that the language compiler simplifies
things by providing a keyword that developers use to plug into the delegate infrastructure.
Events
As you may have guessed by now, delegates are the heart and soul of event handling in .NET.
They provide the underlying infrastructure for asynchronous callbacks and UI events in web
applications under ASP.NET. In addition to the delegate keyword, there is also the event keyword
in C#. The event keyword lets you specify a delegate that will fire upon the occurrence of some
event in your code.


Pages:
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288