You must Sign In to post a response.
  • Category: ASP.NET

    Multicast Deligate

    can any one give me some Good Examples or references regd., Multicast Deligates...???
  • #475499
    Multicast Delegate

    When a delegate is wrapped with more than one method that is known as a multicast delegate.

    In C#, delegates are multicast, which means that they can point to more than one function at a time. They are derived from System.MulticastDelegate class.


  • #475500
    Invoking a multicast delegate asynchronously
    Events, being multicast delegates, are subject to having multiple subscriptions. Invoking these events synchronously is no problem; just raise the event in the usual way. However, if you have to do this asynchronously, then it's much trickier. So here's what to do:

    if ( currentEvent.GetInvocationList().Count() > 1 )
    __foreach (Delegate d in currentEvent.GetInvocationList())
    ____( ( EventHandler ) d ).BeginInvoke( args, new AsyncCallback
    __________( OnEventHandlerCallback ), this );


  • #475510

    Check these links

    Best Regards,
    Vasanth Kani

    Personal Blog:
    Religious Blog:

  • #475511
    A multi-cast delegate is basically a list of delegates or a list of methods with the same signature. A multi-cast delegate can call a collection of methods instead of only a single method.

    public delegate void ExecuteCallback();

    class Executioner
    private ExecuteCallback _doExecute;

    public void AddMultiple()
    // Add a delegate to MethodA
    // This will work even if _doExecute is currently null
    _doExecute += new Execute( MethodA );

    // Add a delegate to MethodB also
    _doExecute += new Execute( MethodB );

    // Add a delegate to MethodC also
    _doExecute += new Execute( MethodC );

    public void MethodA()

    public void MethodB()

    public void MethodC()

    Call a multi-cast delegate

    // Call the delegate like a method
    // This will automatically call each delegate that is part of this multi-cast delegate

    // Iterating through a multi-cast delegate manually

    // Call each delegate in the multi-cast delegate one at a time
    // In order to handle any exceptions that might occur

    // Iterating through a delegate manually is needed in
    // order to continue processing all the delegates even
    // if one throws an exception

    // In this example, any exceptions are ignored and
    // the processing continues with the next delegate
    // In a real world example, the exception would at least be logged

    public void IterateAll()
    if( _doExecute != null )
    foreach( ExecuteCallback doSingleExecute in _doExecute.GetInvocationList() )
    // This delegate threw an exception

    // This technique could also be used for other purposes:
    // To get each return value if the delegate is not void
    // To call all the delegates asynchronously
    // Etc.


  • #475525
    Thanks Mr. Durga Prasd..

    that helps me .. :)

  • #475526
    thanks Paul, thatz helps me even better..

  • #475641
    The C# language has a feature known as the multicast delegate. Any delegate that has a void return type, is a multicast delegate. A multicast delegate can be assigned and invoke multiple methods.

    this.SearchButton.Click += new System.EventHandler(this.SearchButton_Click);
    this.SearchButton.Click += new System.EventHandler(this.NotifyStatistics);

    Every time the user clicks the Search button, first SearchButton_Click() is called, followed by NotifyStatistics(). The event handlers are called in the order they are added. Likewise, using -=, an event handler can be removed.

  • #475670
    This code demonstrate how to use multicast delegate in C#.Net

    public delegate void dname();
    class DelegateDemo
    public void m1()
    MessageBox.Show("From m1");
    public void m2()
    MessageBox.Show("From m2");

    private void button1_Click(object sender, EventArgs e)
    DelegateDemo obj = new DelegateDemo();
    dname d1 = new dname(obj.m1);
    dname d2 = new dname(obj.m2);
    dname d3;
    d3 = d1 + d2;

    Thanks & Regards


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.