When is it useful to have multicast delegates over singlecast delegates?
I use delegates a lot, mainly coupled with C# lambdas, but I've never felt the urge to use the multicast aspect of C# delegates, ie I've never wanted to combine multiple delegates together in a single delegate. I'm therefore very curious in what sort of situation multicast delegates are useful - I can only think of examples in which you can easily implement the functionality some other way, by, say, chaining the delegates or putting them in a list.
In particular, Eric Lippert's answer here gives the impression even the C# team sometimes forgets about the multicastiness of delegates.
Multicast IP Routing protocols are used to distribute data (for example, audio/video streaming broadcasts) to multiple recipients. Using multicast, a source can send a single copy of data to a single multicast address, which is then distributed to an entire group of recipients.
The main advantage of multicast mechanisms versus other possibilities is real time transmission for multiple clients. By using multicast mechanism in these cases, you save an enormous amount of network resources and additionally improve the multicast content transmission.
Multicast addressing can be used in the link layer (layer 2 in the OSI model), such as Ethernet multicast, and at the internet layer (layer 3 for OSI) for Internet Protocol Version 4 (IPv4) or Version 6 (IPv6) multicast.
Unfortunately multicast on the Internet has never really been implemented. These large video companies use LOTS of unicast traffic to deliver videos to their customers. The only place where you might see multicast on the Internet is your local ISP.
Anything acting as an event is the classic answer here - then the caller doesn't need to know who is listening (just invoke it, if it is non-null). This is ideal as multiple operations can subscribe simultaneously - for example 3 separate controls observing (data-binding to) the same property on a view-model.
Any cases where the delegate is acting as a function (in particular with a return value) is trickier, as you need to think about how you will handle that - take the first? Last? Aggregate?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With