Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of multicast in C# multicast delegates

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.

like image 349
Alex ten Brink Avatar asked Jun 09 '11 18:06

Alex ten Brink


People also ask

What is multicast used for?

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.

Why is multicast important?

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.

Where is multicast address used?

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.

Is multicast used today?

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.


1 Answers

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?

like image 138
Marc Gravell Avatar answered Oct 13 '22 00:10

Marc Gravell